Java use interface

格式:public class SubImpl  extends Super  implements IA,IB

Interface can be multiple inheritance, but can only inherit interfaces, not inherited class.

 

Implement the interface (support multi-realization)

[Modifier] class name of the class implements interfaces 1, 2 ... Interface

Implementation of the interface must extends after;

The method of implementation of the interface type must be public

 

Interface can not create an instance, but can declare a reference type variable.

In this case, a reference type variable must point to its implementation class object.

IStudent s = new String();//

IStudent s = new StudentImpl();//

 

 

The relationship between interfaces and classes:

Achieve a relationship or inheritance .

It can be said class implements the interface's methods, it can be said class inherits the interface methods, different interpretations in different situations!

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11131574.html