Can a class be both abstract and final? Why or why not?
No, a class cannot be both abstract and final in Java.
-
abstract
means the class cannot be instantiated directly and must be subclassed. -
final
means the class cannot be subclassed.
Since an abstract class is meant to be extended and a final class cannot be extended, the two modifiers are contradictory.
In short: A class can’t be both abstract and final because they have opposite purposes regarding inheritance.