table of Contents
1. The benefits of inheritance
- Reduce code redundancy and improve code reusability
- Facilitate function expansion
- Provide prerequisites for the use of polymorphism
2. Inheritance format
class A extends B{}
A: subclass, derived class, subclass
B: parent class, base class, super class, superclass
Embodiment: Once the subclass A inherits the parent class B, the subclass A obtains all the properties and methods of the parent class B
Including private methods and properties, but cannot be called because of encapsulation
Three, description
-
One class can be inherited by multiple classes
-
Single inheritance of Java classes : a class can only have one parent class
-
After the child class inherits the parent class, it gets all the attributes and methods declared by the direct parent class and the indirect parent class
-
If a class does not explicitly declare the parent class, then such inherited from
java.lang.Object
classAll classes inherit directly or indirectly in
java.lang.Object
classThought that all these classes have the function of such declaration