override

  • Thread starter Thread starter naveen
  • Start date Start date
N

naveen

Hi
why there are 2 diffrenet types in heritence of defining methods
1. one redefining method of base class using new keyword
2.customizing method using virtual and override keywords

is any one has more advantage then other or does it help compiler in any way

Regards
Naveen
 
Naveen,

They have two different purposes.

using new: You are basically introducing a same named method in a descendant
so effectively you are *not* inheriting. This kind of thing is made possible
by most compilers to ensure code resilience and is not considered
inheritance at all.

virtual/override: This is the inheritance mechanism. Descendant classes have
the option to do one of three possible things:
1. Call the inherited method and then extend it
2. First do the extended implementation and then call the inherited
implementation
3. Ignore the inherited implementation completely and re-implement.
 
Back
Top