When we call a function of an object through a reference, first JVM checks whether the function is there in JVM or not. If the function is present in the object then the JVM searches whether the object has any sub-object or not,

if the object has a sub-object JVM searches whether the sub-object has any other further sub-objects. In this way, it reaches the sub most objects. Now it finds for the function in the sub most objects. If it is found, the function is executed if not control searches for the function in the immediate super class object and so on.

When we call a function of an object through a reference, first JVM check whether the function is present in the object or not, if the function is not present in the object, then JVM searches for the function in the immediate super class object. In this way, if the function is not found even in the super most objects then it generates a compilation error.

If the function is found in either the pointed object or any of the super objects, then the JVM searches whether the object has any sub-object or not, if the object has a sub-object JVM searches whether the sub-object has any other further sub-objects. In this way, it reaches the sub most objects. Now it finds for the function in the sub most objects. If it is found, the function is executed if not control searches for the function in the immediate super class object and so on.

When we call a function which is overridden in three classes via Class A, Class B, and Class C. where B extends A, C extends B then according to our discussion the overridden function in the sub most object gets the highest priority and it is executed first.

 

Super class reference and sub-class object rule Homework Help