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…