Thinking in Java (vi)-Polymorphism

Source: Internet
Author: User

Mechanisms required for dynamic binding

1. Identify the object type during execution

2. Call the corresponding function

 

 

In addition to the final modifier, functions in Java use dynamic binding.

 

Of course, constructor is an exception, and it has no polymorphism.

The formation process of a complex object that contains inheritance and combination is as follows:

1. Allocate heap space and perform automatic initialization. Set all to binary zero.

2. Call the constructor of the direct parent class of the current class cyclically

Until the parent class of the current class is object

Performs Explicit initialization of the current class member, executes the constructor of the current class, and returns to its direct subclass.

This repeats until the last subclass is returned.

Note: The subclass cannot display and initialize the parent class members.

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.