java-Object-oriented 2--inheritance, polymorphic

Source: Internet
Author: User

1. Benefits of Inheritance:

1. Improve code reusability.

2. Create a relationship between classes and classes, providing a precondition for the third-largest feature polymorphism of the object-oriented

Single inheritance is supported in 2.java, and multiple inheritance is not directly supported, but multiple inheritance in C + + is improved. Java is solved by multiple implementations, and a class can implement multiple interfaces.

Single inheritance: A subclass can have only one direct parent class.

Multiple inheritance: A subclass can have multiple direct parent classes that are not allowed in Java, but are modified. Because multiple parent classes have a member with the same name, multiple inheritance produces the uncertainty of the call.

3. When the member and local variables of this class have duplicate names, use this. Distinguish

Use Super when the members of the subclass and the members of the parent class have the same name. Distinguish

This represents a reference to a class object, and super represents the parent class space.

java-Object-oriented 2--inheritance, polymorphic

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.