Java records -14-object-oriented polymorphism

Source: Internet
Author: User

Java Object-oriented polymorphism (polymorphism)

    1. Polymorphism is constructed on the basis of encapsulation and inheritance; polymorphism (also known as dynamic binding, late binding, or runtime bind run-time binding)

    2. The subclass is the parent (the Rose is the flower, the man is the person), so the polymorphic means: the reference of the parent type can point to the object of the subclass;

    3. The parent class is the child class is wrong (flower is the rose, the person is the man is wrong, the other flower does not approve, the woman also does not agree)

    4. People are often plagued by other non-object-oriented features in the Java language, such as method overloading, which are sometimes thought of as object-oriented features. But don't be fooled: if it's not late binding, it's not polymorphic.

    5. Method overloading is early binding, during compilation, Java knows its parameters and types at compile time, and polymorphism is late binding, that is, when running to know, and compile time is not known.

    6. Polymorphism separates the interface and the implementation from another angle by separating "what" and "how". Polymorphism not only improves the organization and readability of the code, but also creates "extensible" programs that can be expanded either when the project is initially created or when new features need to be added.

    7. Encapsulation creates a new data type by merging features and behaviors. Implement hiding separates the interface and implementation through the details "private". This type of organizational mechanism is easier to understand for those who have a procedural programming background. The role of polymorphism is to eliminate the coupling relationship between types. We already know that inheritance allows the object to be treated as its own type or its base type. This ability is extremely important because it enables multiple types (derived from the same base class) to be treated as the same type, and the same code can run on top of these different types without distinction. Polymorphic method calls allow one type to exhibit the difference from other similar types as long as they are derived from the same base class. This distinction is expressed by the different behavior of the method, although these methods can be called by the same base class.


Java records -14-object-oriented polymorphism

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.