I have class B, which inherits from class A. The superclass A is abstract, containing one abstract method. I don\'t want to implement the abstract method in class B, therefore I
In Java, the abstract
class annotation indicates that the class cannot be directly instantiated. A class could be declared abstract
simply because it should never be instantiated (perhaps it contains only static methods), or because its subclasses should be instantiated instead.
It is not a requirement that abstract
classes contain abstract
methods (the inverse is true: a class containing one or more abstract
methods must be abstract
.)
The question of whether you should duplicate the abstract method definition might be perceived as a style question - but I would be hard pressed to come up with an argument in favor of duplicating the definition (the only argument I can come up with is in the case where the class hierarchy might change the semantics or use of the method, and thus you'd like to provide an additional javadoc in class B.)
The primary argument against re-definition of the abstract
method is that duplicate code is bad - it makes refactoring more cumbersome and such (all the classic "don't duplicate code" arguments apply.)