|
Java, extends and implements Usage
1. In the class declaration to create a subclass of the class keyword extends. A class declaration by keyword implements its own use one or more interfaces.
extends inherit a class, then you can use inherit the parent class method, you can also override the parent class method; implements is to implement multiple interfaces, the interface methods are generally empty, it must be rewritten to use.
2.extends is inherited from the parent class, as long as that class is not declared as final or as abstract class definition that will be able to inherit, JAVA does not support multiple inheritance, but you can use the interface to achieve, so we must use implements, inherited only inherit a class, but implements can implement multiple interfaces, separated by a comma on the line
3. extends, the parent class can be called the father of initialization this.parent (). And will override the parent class defined variables or functions. Such benefits are: architect defined interface that allows engineers to achieve it. The entire project development efficiency and reduce development costs significantly. And implements, to achieve the parent class, subclass can not override the method or variable of the parent class. Even if the parent class subclass definition and the same variable or function, the parent class will be substituted out.
Summary: Both implementations specific use, is to look at the actual situation of the project, the need to achieve, can not be modified implements, need only define the interface implementation, may be modified or extended good use extends. |
|
|
|