Polymorphism of the three major features in java, and java feature Polymorphism

Source: Internet
Author: User

Polymorphism of the three major features in java, and java feature Polymorphism

I. Polymorphism: an object has multiple manifestations (the reference type variable of the parent class points to the object of the subclass)

2. multi-state conditions: 1. There must be an inheritance relationship 2. There must be method rewriting.

Iii. int [] a; // a reference type variable --> // reference the variable of the in type array

4. Variables of reference type: array, String, Object

Animal class, Dog, Fish

Animal a = new Dog [Fish]; // The manifestation of Polymorphism

5. Notes for using polymorphism:

1. In the case of polymorphism: The child parent class has a member variable with the same name. By default, it is a member variable in the parent class accessed.

2. In the case of polymorphism: the sub-parent class has non-static methods with the same name and accesses non-static methods of sub-classes.

3. Polymorphism: The child parent class has a static method with the same name.

4. In the case of polymorphism: the unique member of the subclass cannot be accessed.

Summary: in the case of polymorphism, if a child parent class has members with the same name, all the Members are accessing the parent class, except that non-static methods with the same name are access subclasses.

Caused by java compiler compilation principles

Compile to the left, and run not necessarily to the right

Compile to the left: the java compiler will check whether the reference type contains specified members during compilation. If not, an error will be reported.

 

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.