How to force a method to be overridden in java?

后端 未结 5 2197
忘掉有多难
忘掉有多难 2020-12-15 02:36

I have to create a lot of very similar classes which have just one method different between them. So I figured creating abstract class would be a good way to achieve this. B

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 03:02

    If you have an abstract class, then make your method (let's say foo abstract as well)

    public abstract void foo();
    

    Then all subclasses will have to override foo.

提交回复
热议问题