Let\'s say Java has these hierarchical classes:
class A
{
}
class B extends A
{
public void m()
{
System.out.println(\"B\\n\");
}
}
clas
What's the logic behind the Java designer's decision to print C-C-C instead of B-C-C? I mean, why reference B uses the overriding method in C? What's the advantage of this approach?
Look that you call method from D class object which inherited the M method from C class. The reference type doesn't matter in Java - the important part is which class has referenced object.