Monday, July 16, 2007

What's the difference between override and new?

  • When a virtual method is called on a reference, the actual type of the object that the reference refers to is used to decide which method implementation to use.
  • When a method of a base class is overridden in a derived class, the version in the derived class is used, even if the calling code didn't "know" that the object was an instance of the derived class.
  • If you use the new keyword instead of override, the method in the derived class doesn't override the method in the base class, it merely hides it.

No comments: