Quote:
MainClass obj = new DrivedClass();
In the above line
obj
is declared of
MainClass
type. Then it is assigned with a
DrivedClass
instance.
That's legal (indeed the compiler doesn't complain), however, due to its very type, you cannot directly invoke on
obj
the
DrivedClass
methods. You may however write something like:
DrivedClass sameobj = obj as DrivedClass;
sameobj.Add();