One of the three main features of Java: polymorphism

Source: Internet
Author: User

Before our article on the Java Packaging and inheritance, encapsulation, and did not reflect the strength of the package, but also carefully use encapsulation. Because the package is not yet associated with polymorphism, there is no way to see the upside of the transformation.
Polymorphism means that the same behavior has many forms of expression. The same method produces various results depending on the calling object. For Java, polymorphism is the reference variable defined in the program, and the code that invokes the method is determined at compile time, but the object that the reference variable points to is determined at run time. To give a very simple example, one has to work. Work here is a method, but a writer's job is to write an article, a programmer's job is to write code. The work of the performer is different, the content of the work is different. This is a polymorphic.

Multi-State implementation

For us, the implementation of polymorphism should be prepared as follows.

  1. Inherited
  2. Method overwrite
  3. Upward transformation

For Java, it is implemented by dynamic binding. Let's take a look at what dynamic binding is, so that you can easily use polymorphic features later.

Dynamic binding

Binding refers to associating a method call with the same method body.
Dynamic binding is the value at run time according to the type of object binding, and the corresponding is static binding, binding at compile time, in Java only the final static private and the construction method is statically bound.
We already know that the invocation of a generic method is called at run time based on the type of the object, in other words, no matter what you write in the code, at run time it really determines which object is calling the method.

One of the three main features of Java: polymorphism

Related Article

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.