Should an abstract class have at least one abstract method?

前端 未结 5 2107
眼角桃花
眼角桃花 2021-02-02 12:17

Is it necessary for an abstract class to have at least one abstract method?

5条回答
  •  无人及你
    2021-02-02 13:06

    In JDK 1.0 it was indeed necessary to have at least one abstract method in an abstract class. This restriction was removed in JDK 1.1 (1997? (I'm old)) and such classes added to the Java library, such as java.awt.event.KeyAdapter.

    In C++ you need at least one pure virtual function to make a subclass necessary, and at least one virtual function to add RTTI to the class. Typically it makes sense to use the destructor.

    Note when overriding non-abstract methods, using @Override is a good idea. It not only tells the reader important information about what the code is attempting to do, but also spots common errors where typos or incorrect parameter types prevents the override.

提交回复
热议问题