关于Java的抽象类

由于对Java抽象概念的理解不够深入,我进行了学习。

特点

– 无法直接创建实例。
– 强制子类进行重写。
– 子类需要编写构造函数。

abstract class Abst_sample {
    abstract void abstractMethod(int num, String str);
    void nonAbstractMethod() {
        System.out.println("非抽象メソッドより出力");
    }
}
public class sample extends Abst_sample {
    public static void main(String[] args) {
        sample aaa = new sample();   
// 継承したあとで、自身のインスタンスを生成してabstractMethod を呼び出している。
        aaa.abstractMethod(3, "Test");
    }
    @Override
    public void abstractMethod(int num, String str) {
        System.out.println("引数int num = " + num + " / 引数String str = "+ str);
    }
}

我想给出的指示是使用这种方法。

如果要进行多人开发,可能也会需要这样的功能。

记住这个是无损的。

请参考