13_接口和抽象类的区别

interface Itfce {
    public void x();
}

abstract class Abs {
    public static void f1() {
        System.out.println("Static 1 ");
    }
    public abstract void a1();
    public void a2() {
        f1();
    }
}

class C1 extends Abs implements Itfce{
    @Override
    public void a1() {
        //    Class 'C1' must either be declared abstract or implement abstract method 'a1()' in 'Abs'
        System.out.println("必须实现 抽象父类的 抽象方法 a1()" );
    }

    @Override
    public void x() {
        //Class 'C1' must either be declared abstract or implement abstract method 'x()' in 'Itfce'
        System.out.println("必须实现接口的所有方法 x()");
    }
}


public class Interface_test {
    public static void main(String[] args) {
        C1 c = new C1();
        c.a1();
        c.x();
        c.a2(); //抽象类可以实现方法 a2
    }
}

13_接口和抽象类的区别

 

 

https://blog.csdn.net/zhangquan2015/article/details/82808399

https://www.runoob.com/java/java-abstraction.html

 

上一篇:JAVA实验六——图形用户界面设计——6-47选择整数计算


下一篇:机器学习sklearn(90):算法实例(47)分类(26)XGBoost(四)XGBoost的智慧(一)