An abstract class can have any number of abstract methods, including zero. There is no requirement that an abstract class must contain at least one abstract method. It may have only concrete (implemented) methods and still be declared abstract to prevent instantiation and to serve as a base class for subclasses
. Key points:
- An abstract class is declared with the
abstract
keyword and cannot be instantiated directly. - It may contain a mix of abstract methods (which have no body and must be implemented by subclasses) and concrete methods (which have an implementation).
- It is legal and sometimes useful to have an abstract class without any abstract methods; this can be used to prevent direct instantiation or to provide shared functionality for subclasses
- Each abstract method declared in an abstract class must be implemented by any concrete subclass
For example, in Java:
java
abstract class GraphicObject {
abstract void draw(); // abstract method
void moveTo(int x, int y) { /* concrete method */ }
}
But an abstract class may also have no abstract methods:
java
abstract class Base {
void commonMethod() { /* implementation */ }
}
In summary, there is no fixed number of abstract methods required in an abstract class; it can have zero or more abstract methods depending on design needs