When to use new and when to use override???

  • Thread starter Thread starter Bob Rock
  • Start date Start date
B

Bob Rock

Hello,

it is not clear to me when to use new and when to use override (on a virtual
method). Could someone explain when to use each. Also it is not clear to me
if the hidden or overriden (base) method is still accessible. Thx.

Bob Rock
 
Bob Rock said:
Hello,

it is not clear to me when to use new and when to use override (on a virtual
method). Could someone explain when to use each. Also it is not clear to me
if the hidden or overriden (base) method is still accessible. Thx.

Never use "new" on a virtual method. Use "virtual" when introducing the
method (i.e.when no ancestor class defines the same method) and "override"
when overriding it (i.e.when some ancestor class defines the same method,
even abstractly).

The closest ancestor version of the method is accessible using the "base"
keyword. None of the others are.
 
Back
Top