接口与抽象类的继承

来源:互联网 发布:piano软件 编辑:程序博客网 时间:2024/05/13 19:08
1.抽象类可以继承抽象类
2.接口可以继承接口
3.接口不能继承抽象类
4.抽象类可以实现接口

5.抽象类可以继承具体类

//接口A
public interface A {
    public void go();
}

//抽象类B
public abstract  class B  extends C implements A {
     public abstract void run();
    
}

//具体类C
public class C {
public void eat(){
System.out.println("eat");
}
}

//测试D
public class D extends B {
public void go(){
System.out.print("go");
}
public  void run(){
System.out.println("run");
}
public static void main(String[]args){
D test=new D();
test.go();
test.run();
test.eat();
}
}


原创粉丝点击