1. Concept of inheritance
- One of the object-oriented features, you can implement the reuse of the class. The following two ways can be implemented
- A. Composition/aggregation relationship (contains other classes): Treats a class as a property of another class.
- B. Derived classes: One class inherits another class, and the class that implements the inheritance is called the derived class, and the inherited class is called the parent class, the base class, and the superclass.
- The member methods and member variables of the parent class inherit from the quilt class, but the parent class's construction method is not inherited.
- Only single inheritance is supported in Java, and C + + multiple inheritance is not the same.
2.super keywords
1.super can access member variables of the parent class
2.super can call a member method of a parent class
3.super you can call the constructor of the parent class in the subclass construction method
Note:super can only be used in member methods and construction methods, not in the static method (and this is the same),
Used in the construction method must be placed in the first row.
3.this and Super keyword comparisons (neither can be called in the static method)
4. Method overrides
- Method overrides exist only between subclasses and parent classes
- When a subclass overrides a method of a parent class, access permissions cannot be scaled down, can be enlarged, and other ways of writing
- Static methods of a parent class cannot be overridden by a quilt class as a non-static method
5. Access rights
Access modifiers for class
- Public: Classes in any package (that is, all classes) can access the class
- Default value: Classes in the same package can access the class
Access modifiers for Members
- Private: Only visible to this class, sub-class is not seen
- Default value: Visible to classes in the same package
- Protected: Visible to classes and all subclasses in the same package
- Public: Visible to all classes
Note: Access to members is a prerequisite for accessing the class where members are located
java-Object-oriented article 2