Inherited advantages: code reuse
inherited disadvantages:
Features: Java is a single inheritance he had only one direct parent
of all classes inherit the Object
What is inherited?
Inherited premise is a sub-class is a parent class is an animal swallows
exctends
public the extends the Person class Teacher
sub-class has all the attributes and methods of the parent class's
note: private will be inherited
Relationship inheritance:
1. Write parent
2. Write subclasses: class inherits the parent
3. constructor call parent class
4. The method of rewriting
5. Construction subclass object
using keywords 6.super
configured to call the parent class Parent the class must have a constructor
call the property or method of the parent class
Parent Class: larger, but less data
name age sex
subclasses: a more accurate range (small), but more data
name, sex, age, subject, teachAge, salary
Note: Only 1 constructed subclass method calls the constructor of the parent class
2. the first sentence must be placed
When building a subclass of objects
1. Build a good parent objects class
2. Build your own
When the subclass does not own getName ()
actually this.getName () is super.getName ()
Method override:
1. In the inheritance relationship
2. subclasses have the same process (a higher access modifier [b] a subclass return parent class type parameter c d e method name thrown..... abnormal)
3. the details of the implementation of nowhere