@see abstract class
1.interface定义了抽象方法和常量
2.默认interface里面的函数都是public abstract。根据习惯,这两点就不写出来了。
3.data fields默认是public static final。根据习惯,这三点就不写出来了。
4.一个class要使用某一个interface,那么他需要一个implements
eg class TestForInterface implements AnInterface(){}
5.interface也可以相互继承,还可以继承多个,一个class可以实现多个接口.
6.uml,继承(类之间,接口之间)用实线,实现接口用虚线.interface要<< interface >>标注出来
7.uml之中接口只有method,没有attribute
8.和抽象类一样,通过对于上级的引用来实现方法.此处,下级类就是这样实现接口的.
Device dev=new StopWatch(…);
Device是接口,StopWatch是类.
比较抽象类和接口.
同:抽象方法
异:抽象方法可以有实体变量和实体方法
接口不能有构造方法
如果一个类继承了一个抽象类,那么他就不能够继承其他类.
如果一个类继承了一个接口,那么他可以使用其他接口,还可以继承类.
interface extends interface1, interface2
class extends class1
class implements interface1,interface2