Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand dynamic binding and static binding in Java Polymorphism

Shulou Source: shulou.com Published: 2022-06-02 10:28:33 10月26日 Update

How to understand the dynamic binding and static binding in Java polymorphism, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

In polymorphisms: member variables and static methods are compiled and run on the left; member methods compile on the left and run on the right, which is why

There are two binding methods in Java, one is static binding, also known as early binding. The other is dynamic binding, also known as late binding.

1. Static binding occurs at compile time and dynamic binding occurs at run time

two。 Variables or methods decorated with private or static or final, using static binding. Virtual methods (methods that can be overridden by subclasses) are dynamically bound based on the object at run time.

3. Static binding is done using class information, while dynamic binding is done using object information.

4. The method of overloading (Overload) is done using static binding, while the method of overriding (Override) is done using dynamic binding.

5. Waiting for binding determines which variable to use or which method to call at compile time; dynamic binding is running to confirm which method is more appropriate to call, which is a selective process, because in polymorphic subclasses, methods of the parent class are overridden, so multiple methods with duplicate names appear, and which method is more suitable for the subclass object is confirmed according to the subclass object when called.

After reading the above, have you mastered how to understand dynamic binding and static binding in Java polymorphism? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Method dynamic static run polymorphic subclass object compilation variable content member is in more problem appropriate helpless for this information reason right Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MySQL macOS Docker NVidia