1. Definition
Inheritance in Java is single, a subclass can have only one parent class , and the parent class of all classes in Java is java.lang.Object, except for this class, each class can have only one parent class;
and a parent class can have more than one child class, can be inherited by multiple subclasses;
Java only supports single inheritance, which means that a class cannot inherit multiple classes.
Java only supports single inheritance (inheriting basic classes and abstract classes), but we can implement them with interfaces (multiple inheritance {implementation} interfaces), and script structures such as:
public class One extends Parent implements two,three,four{}
2. Attention
As a subclass, an instance of a has all the member variables of the parent class B, but for private member variables, subclass A does not have access rights, which guarantees the encapsulation of B.
Keyword extends (that is, inheriting classes), subclasses can inherit all the methods and properties of the parent class, but cannot use private (private) methods and properties.
3, instanceof "Judge---is a sub-category?" Yes true, otherwise false "
1 New children (); 2 New Parent (); 3 New Children (); // parent class declaration, subclass Creation 4 instanceof Parent); 5 instanceof Parent); 6 instanceof Parent);
The resulting results are:
true true true
4. Implements Realization class
Inheritance relationships in Java