Dynamic binding of JAVA

The calling process of JAVA dynamic binding

(1) The compiler looks at the declared type and method name of the object. And will list
all the methods of the class with the name
(2) The compiler looks at the types of the parameters, and in the methods found, the types and numbers of matching parameters are the same. This process is called overload resolution
(3) )
1" If it is a private, static, final method, the compiler can accurately know which method should be called, this process is called static binding
2" If it is not the above method, it will use dynamic binding call method, virtual machine call and The actual type of the object is the most suitable method of this class. If the actual type is class B and class B is a subclass of class A, the virtual machine will first find the corresponding method in class B. If there is no such method in class B , Will go to the A category to find, and so on.

Guess you like

Origin blog.csdn.net/Walker7143/article/details/106003588