Inheritance of the three main features in java and the inheritance of java features

Source: Internet
Author: User

Inheritance of the three main features in java and the inheritance of java features

Inheritance features: inherits the attributes and methods of the parent class. Single inheritance (Multi-Level inheritance) Multi-inheritance in c ++

Feature: Method Rewriting)

The Inheritance in java is the same as in OC.

For example, a human can raise a dog;

People ----> dogs: overall and partial (ownership) relationships.

Team ----> players: the relationship between the whole and the part. Code is the most common

Relationship between has

Student ----> Student: The student is a person. It indicates whether there is an inheritance relationship, and whether the relationship is displayed or not.

How to determine whether there is an inheritance relationship between two things: is a, who is, who is, and whether it is true. If it is set up, there is an inheritance relationship.

A: B: The Inheritance Method in OC

How to express the inheritance relationship in java:

Use keywords: extends to represent inheritance.

Inheritance: Use keywords: extends

Structure:

Class A extends Class B: Class A inherits Class B.

Notes for inheritance:

1. Do not inherit for inheritance, do not save Code, any class inherits

2. The private member variables of the parent class cannot be inherited.

3. the constructor of the parent class cannot be inherited.

4. When a subclass calls its own constructor, it calls the non-argument constructor in the parent class by default.

Related Article

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.