Inheritance (extends)

Here Insert Picture Description
Inheritance (extends):
Inheritance is a derived class of another class, was sent to give birth to a class is called the parent class, derived class is called a subclass. Parent, also known as super class and product classes, subclasses, also known as a derived class.
Create a subclass object is the default first call the parent class constructor, and then call the constructor of a subclass.

1, in line with is-a relationship.
2, use the extends keyword.
3, code reuse.
It can not be inherited parent class members:
1, Private members
2, subclass the parent class is not in the same package, using the default member access.
3, the configuration method.
First, the method overrides:
1, the same method name.
2, the same parameter list.
3, the same type or is a subclass of the return value.
4, access rights can not be stricter than the parent.
Second, the access modifier:
1, Private private.
2, friendly default.
3, protected protected.
(1), properties and methods can be modified.
(2), ponley same package, subclasses can access.
4, public public.
Three, super keyword
1, super can only appear in the sub-category method and the constructor.
2, call the constructor super, only the first sentence.
3, private members can not access the super subclass.
Four, final qualifier:
1, modified class can not be inherited.
2, a modified method can not be overridden by subclasses.
3, modified variable becomes constant, can only be assigned at initialization time.
V. abstract classes and abstract methods:
1, abstract class that can not be instantiated.
2, there may be from 0 to more abstract methods.
3, non-abstract class for all abstract methods of the parent class must be rewritten.

The method may also be used to abstract - abstract method
1, the method is not an abstract method thereof.
2, abstract methods must be abstract class.
3, the abstract methods must be implemented in a subclass, unless the sub-class is abstract.

Characterized in abstract class:
1, abstract class that can not be instantiated.
2, the method may have the abstract class method body
(General Methods), or may not
(abstract method).
3, the method must be implemented in an abstract subclass
(must be rewritten),
the general procedure can be rewritten may not be rewritten.
4, abstract methods must be abstract class.

Published 31 original articles · won praise 0 · Views 365

Guess you like

Origin blog.csdn.net/weixin_45864941/article/details/103737565