Object Oriented Inheritance

1, What is class inheritance?

Inheritance is one of the most prominent features of object orientation. Inheritance is a new class derived from an existing class. The new class can absorb the data attributes and behaviors of the existing class, and can extend new capabilities.

For example, you can define a class called car first. The car has the following attributes: body size, color, steering wheel, tires, and two classes, car and truck, are derived from the car class, adding a small trunk for the car, and for the truck. Add a large cargo box.

Java inheritance characteristics: 
(1) The inheritance relationship is transitive. If class C inherits class B, and class B inherits class A (multiple inheritance), then class C has both the attributes and methods inherited from class B, as well as the attributes and methods inherited from class A,
and can also have its own new Defined properties and methods. Inherited properties and methods, although implicit, are still properties and methods of class C. Inheritance is the most effective way to construct, build and extend new classes on the basis of some more general classes.
 
(2) Inheritance simplifies people's understanding and description of things, and can clearly reflect the hierarchical relationship between related classes.
(3) Inheritance provides software reuse function. If class B inherits class A, then only a few features (data members and member methods) that are different from the base class (class A) need to be described when creating class B. This approach can reduce the redundancy of code and data, and greatly increase the reusability of the program.

(4) Inheritance reduces the interface and interface between modules by enhancing consistency, which greatly increases the ease of maintenance of the program.

(5) Provide multiple inheritance mechanism. In theory, a class can be a special class of multiple general classes, and it can inherit properties and methods from multiple general classes, which is multiple inheritance. 
For the sake of security and reliability, Java only supports single inheritance, and implements multiple inheritance by using the interface mechanism.
 
 
 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325290066&siteId=291194637