A
A
Ali Kartoev2015-07-24 18:40:35
Java
Ali Kartoev, 2015-07-24 18:40:35

Did I understand correctly how the method call from the reference of the parent class type works?

When a method is called from a reference of the parent class type, the compiler first checks whether such a method is declared in the type of the reference variable, and then checks whether such a method exists in the object referenced by the variable. If the method is overridden in the object, then this method is called, if not, then the method described in the type of the reference variable. Right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evhen, 2015-07-24
@EugeneP2

This is determined not by the compiler, but at runtime. This is called dynamic linking.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question