Inheritance in the Java language

Source: Internet
Author: User

I. The concept of succession

Inheritance refers to the definition of a class can be based on another already existing class, that is, the subclass is based on the parent class, so as to implement the reuse of the parent code, the subclass can absorb the existing classes of data properties and behavior, and can expand the new capabilities.

            

Second, the invocation of the constructor method in the inheritance

The subclass constructor method always first calls the parent class construction method

By default, the parent class is called without a parameter construction method

You can use the Super keyword to call any of the constructor methods of a parent class in the first row of a subclass construction method

Third, super and this keyword

Super Keyword: We can use the Super keyword to implement access to a parent class member to refer to the parent class of the current object.

This keyword: point to your own reference.

            

            

Iv. Methods of coverage

Subclasses can override one of the methods in the parent class, called method overrides, also called method overrides, which is a very important point of knowledge in inheritance. A method override can be used if a subclass needs to modify the method body of a method inherited from a parent class.

Method override principle: same name, same parameter, same return value, access permission cannot be reduced

Inheritance in the Java language

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.