Inheritance of three object-oriented features

Source: Internet
Author: User

Inheritance of three object-oriented features

Inheritance is a concept in object-oriented software technology. If a Class A inherits from another class B, this class A is called the Child class of B, and B is called the parent class of. Inheritance allows the subclass to have various attributes and methods of the parent class without having to write the same code again. When the subclass inherits the parent class, you can redefine some attributes and rewrite some methods to overwrite the original attributes and methods of the parent class, make it have different functions than the parent class. In addition, it is also common to append new attributes and methods to child classes.

Some programming languages support multi-inheritance, that is, a subclass can have multiple parent classes at the same time, such as the C ++ programming language. In some programming languages, A subclass can only inherit from one parent class, such as the Java programming language. In this case, you can use interfaces to achieve similar effects as multi-inheritance.

 

Inheritance concepts can be implemented in three ways: Implementation inheritance, interface inheritance, and visual inheritance.

Implementation Inheritance refers to the ability to use the attributes and methods of the base class without additional encoding;

Interface inheritance only uses the names of attributes and methods, but the subclass must provide implementation capabilities;

Visual Inheritance refers to the ability of sub-forms (classes) to use the appearance of base Forms (classes) and implement code.

 

Why inherit?

 

1. code reuse (subclass can inherit the public members of the parent class)

2. polymorphism (mentioned later)

Inheritance features:

 

1. Single inheritance (that is, each subclass can have only one parent class, while one parent class can have multiple child classes)

 

2. Inheritance (Child classes can inherit the common members of the parent class)

 

3. The subclass cannot inherit the constructor of the parent class (No parameter constructor of the parent class is called by default)

 

All classes inherit the object class by default. (If a class does not show a class, it inherits from the object class by default)

 

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.