The polymorphism of Java

Source: Internet
Author: User

Polymorphic: The reference to the parent class is directed to the object of the child class.
* Reference to Parent class: One refers to the parent class variable pointing to that memory space
* Two: The parent class has its own type information table, which is owned by any object, and is independent of inheritance polymorphism.
* Subclass object: One refers to the heap memory space of the subclass
* Two: Also refers to the subclass of the Type information table
* Polymorphic (Upward transformation): is to invoke the parent class object's type information table to call the subclass Type information table and the same member method of the parent class
* So-called same, that is, before subclasses overwrite/override parent class methods
* A member method that is not in the parent class information table is not called.
* static method, static data, member variable and this is irrelevant. The parent class reference accesses all variables and methods in the parent type, whether it is a member or a static
* Parent Class A = new subclass (); What do you want to know about the parent class object?
* After a downward transformation, replace the type information table of the parent class with the subclass's type information table, so that all the variables and methods in the seat class object can be completely
* Parent Type Information table access,
* After the transition, access the sub-type information table
* Do not transform, you can access the member methods in the subclass after overwrite
*
Note
* Polymorphism in the client class and class library class differences
* Client class: The class that contains main () is called the client class
* First in the class library class, there is an inheritance relationship, and the subclass overrides the method of the parent class
* Then, in the client class, point to the object of the child class with a reference to the parent class

In Polymorphic, only member methods are involved
* Member variable: not involved
* Construction method: Does not inherit at all, so it does not involve
* Static method: Static method also does not inherit, belong to the whole type

The polymorphism of 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.