is a variable that can hold an instance of
- which includes any class which is derived from it.
is derived from
, which in turn derives from
when you create an instance of ClassC, you can assign it to
- but that doesn't change the instance, it just means you can only call
methods on it.
When you call
, the system looks for the highest method with a matching signature in the inheritance chain - which is the
version which overrides the
, it creates a new method of the same signature that "hides" the previous versions.
If you do this instead:
public static void Main()
classC c = new classC();
classA a = c;
You will get the
methods called because the first is looking for the
version (overridden by
)and the second is specifically looking for the