给楼主看一个例子,应该就会明白了:代码如下:
- interface Inter//接口Inter
- {
- public static int NUM = 3;
- public abstract void show();
- }
- interface InterA//接口InterA
- {
- public abstract void show();
- }
- class Demo//类Demo,设为父类
- {
- public void function(){}
- }
- class Test extends Demo implements Inter,InterA//子类Test继承父类Demo再实现了接口Inter和InterA,单继承多实现
- {
- public void show(){}
- }
- interface A
- {
- void methodA();
- }
- interface B //extends A//接口之间可以继承
- {
- void methodB();
- }
- interface C extends B,A//而且可以多继承
- {
- void methodC();
- }
- class D implements C
- {
- public void methodA(){}
- public void methodB(){}
- public void methodC(){}
- }
- class InterfaceDemo
- {
- public static void main(String[] args)
- {
- Test t = new Test();
- System.out.println(t.NUM);
- System.out.println(Test.NUM);
- System.out.println(Inter.NUM);
- }
- }
复制代码 归纳两点:
1、子类可以单继承父类并同时实现多个接口;
2、接口可以多继承接口;
|