Inheritance of the 3 major features in Java

Source: Internet
Author: User

Inheritance features: Inherits the properties and methods of the parent class. Single Inheritance (Multilayer inheritance) inheritance in C + + is multiple inheritance

Properties: Replication of methods (Overrides)

Inheritance in Java is the same as in OC.

For example: people can keep dogs;

People----> Dogs: Overall and partial (own) relationships.

Team----> Players: Overall and part of the relationship. The code is the most common

Has a relationship

People----> Students: Students are people: the existence of an inheritance relationship, whether the bottom of the show, there are specific circumstances to decide.

How to tell if there is an inheritance relationship between two things: is a who is who is set up. The establishment has the inheritance relationship.

A:B: The notation of inheritance in OC

How inheritance relationships are represented in Java:

Use keyword: extends to represent inheritance.

Inheritance: With keyword: extends

Structure:

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

Considerations in Inheritance:

1. Do not inherit for inheritance, do not want to save code, any class is inherited

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

3. The method of constructing a parent class cannot be inherited.

4. When a subclass calls its own constructor method, the non-parametric constructor method in the parent class is called by default.

Inheritance of the 3 major features in 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.