Method Bindings for Java

Source: Internet
Author: User

1. Program bindings:
Binding refers to the invocation of a method associated with the class (method body) in which the method resides. For Java, bindings are divided into static and dynamic bindings, or pre-and late-binding.
2. Static bindings (pre-bind/compile-time bindings):
The method is already bound before the program executes, and is implemented by the compiler or other linker. For example: C.
For Java simple can be understood as the program compile time of the binding; In particular, the Java method is only final,static,private and the constructor method is pre-binding
3. Dynamic binding (late binding/Runtime binding):
Binds at run time based on the type of the specific object. If a language implements late binding, it must also provide mechanisms to determine the type of the object during run time and invoke the appropriate method, respectively. That is, the compiler still does not know the type of the object at this point, but the method invocation mechanism can investigate itself and find the correct method body. Different languages have a difference in how late binding is implemented. But at least we can think of it: they all have special types of information in the object.
The process of dynamic binding:
-The virtual machine extracts the actual type of object from the method table;
-Virtual machine search method signature;
-Call method.
4. Summary:
In Java, almost all methods are late-bound, and the dynamic binding method is either a subclass or a base class at run time. But there are also special, for the static method and the final method because cannot be inherited, so at compile time can determine their values, they belong to the early bound. Specifically, the method and member variables of the private declaration cannot be inherited by the quilt class, and all private methods are implicitly specified as final (we can also know that the method is declared as one of the final types to prevent the method from being overwritten. The second is to effectively close the dynamic bindings in Java. Late binding in Java is implemented with the JVM, and we don't have to explicitly declare it, and C + +, which must explicitly declare a method with late binding.
The upward transformation or polymorphism in Java is achieved through dynamic binding, so the dynamic binding is understood, and the upward transformation and polymorphism are done.
As we've already said, for the methods in Java, except for the Final,static,private and constructor methods, all the other methods are dynamically bound. The typical dynamic binding occurs under the transformation declaration of the parent class and subclass: Parent p = new Children ();



Method Bindings for Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.