Suppose I have this code:
BaseClass baseClassVar = new DerivedClass();
baseClassVar.OverloadingMethod();
Both BaseClass
and DerivedClass
have one method called OverloadingMethod
.
If we create an instance of DerivedClass
and store it in a BaseClass
variable; then call OverloadingMethod
, it will call the method in base class.
If so we can assume baseClassVar
is a type of BaseClass
, and it does sounds logical. But viewing the object in debug or call GetType()
actually return a type of DerivedClass
. How does it work like that?