inherit
1. [ Concept ]
In layman's terms, the son inherits Laozi's property, which is one of the principles of opening and closing.
parent class: base class
Subclass: Derived class
Features:
A single-rooted subclass can only inherit from one parent class
A transitive subclass inherits all method properties of the parent class
When creating a subclass object, the subclass object will create the fields of the subclass and the superclass to provide space.
Richter substitution:
Subclasses can inherit everything from the parent class, including constructors, method fields, etc., and can be overridden, but the parent class cannot inherit from the subclass.
The parent class reference points to the child class object, which can only be seen and cannot be used.
example:
Parent p=new Son()
Son s=(Son)p;
explain:
The things in the subclass are more detailed than the superclass, the behavior of the subclass is not in the superclass, and the reference points only point to a separate part of the superclass in the subclass object.
Adaptation diagram:
class adapter
object adapter
The difference between assembly and inheritance