Are there any reasons to have an abstract class with every method in the class defined?

后端 未结 7 705
名媛妹妹
名媛妹妹 2021-02-05 01:42

It seems that an abstract class means the definition of the class is not complete and hence cannot be instantiated.

And I saw some simple Java code which has an abstract

7条回答
  •  长发绾君心
    2021-02-05 02:28

    You might have some classes that don't make sense in the context of your application but they do in the design. A silly example: Abstract class animal, implement born and die. You don't want an "animal". You want a Dog. This way you don't have to repeat the code each class you add. Now you can have Dog, Cat or whatever you want, this would be a good reason, anyway it's hard to find.

提交回复
热议问题