c# - Why can a method marked that is hiding an implementation in the base class call the hidden method? -
i've been doing little reading around c# spec, , come across scenario didn't expect, , hoping share light.
i stumbled across new
keyword hiding members of base class within derived class, , subsequently few discussions on when use new
opposed override
on virtual
member.
i threw little code sample in ide, expecting see compilation error
public class basetype { public void method() { // nothing } } public class derivedtype : basetype { public new void method() { base.method(); } }
but instead found legal c#. since derived class has hidden presence of method()
, why still allowed call it?
cheers
the derivedtype
hiding method classes inheriting derivedtype
, , not itself.
note that, hide method, class has know there exists method in it's parent class same name , same arguments. hence 1 class hiding method it's own scope illogical.
Comments
Post a Comment