I think you are getting confused with the technicality of the words in the answer.
There are two things here,
- Most derived version of the method in context of the derived class being instantiated.
So if you do ,
A a = new B();
a. print(); // this will invoke the method on the class B,
// since instance of class A has reference to instance of B.
and if you do the following:
A a = new C();
a. print(); // Should call the method on class C, since base class has reference to to the instance of C.
Similarly, a more intuitive way of putting it is:
A a = new A();
a.print(); // this will call the method print in class A irrespective of whether this method was overriden in one of the derived classes.
This is the premises of dynamic polymorphism, wherein, the client can call the method print() on base class object of A
without needing to know if A has reference to B or C. The behaviour changes dynamically in client code.
- Alternatively, you could also think about most derived version in the following way:
Suppose the method print() was not overriden in C, but was overriden in B,
then the most derived version of print() will be in class B. The following snip should be helpful.
class A
{
public virtual void print()
{
Console.WriteLine("A called");
Console.Read();
}
}
class B :A
{
public override void print()
{
Console.WriteLine("B called");
Console.Read();
}
}
class C : B
{
public void somerandommethod()
{
// some random method not really relevant to this example.
}
}
static void Main(string[] args)
{
A a = new C();
a.print(); // it will now print B (since B has the most derived implementation of print())
}
Hope this answer helps.
Best.