Woodstock Blog

a tech blog for general algorithmic interview questions

[Java OOP] Can Abstract Class Have 0 Abstract Method?


An abstract class is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.

with NO abstract method?

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.

So, no abstract method is fine. Doing it prevents you from instantiation - you can only inherit.

However, different opinions are:

is subjective and a matter of style. Personally I would say yes. If your intent is to prevent a class (with no abstract methods) from being instantiated, the best way to handle this is with a privateprotected constructor, not by marking it abstract.

how about abstract variable?

There is no such thing in Java.

For more on abstract class, read [Java OOP] Template method pattern.