What is an Abstract Method?
Learn what an abstract method is in Java — abstract classes, interfaces, and mandatory subclass implementation — with a clear code example.
Expected Interview Answer
An abstract method is a method declared with a signature but no body, defined only inside an abstract class or interface, which every concrete subclass or implementing class is required to provide a real implementation for.
Declaring an abstract method forces the enclosing class itself to be marked abstract, meaning it cannot be instantiated directly — it exists purely to define a contract that subclasses must fulfill. In Java, an abstract method uses the 'abstract' keyword and ends with a semicolon instead of a method body; interface methods are implicitly abstract unless marked default or static. A concrete class extending an abstract class must override every inherited abstract method or itself remain abstract. This is the core mechanism of abstraction in Java-family languages: the abstract class or interface defines what must be done, while each concrete subclass defines how it is actually done, letting calling code depend on the stable abstract type while swapping implementations freely underneath.
- Forces every concrete subclass to fulfill a required behavior contract
- Prevents accidental instantiation of an incomplete type
- Lets calling code program against a stable abstract type regardless of the concrete implementation
- Makes intended extension points explicit and self-documenting in the codebase
AI Mentor Explanation
A national coaching curriculum specifies that every certified "All-Format Player" must be able to perform a matchWinningShot(), but the curriculum document itself teaches no specific shot — it only lists the mandatory skill. Only when a specific player, like a real batter who has actually trained a signature shot, completes the curriculum can they be certified as a genuine All-Format Player. An abstract method is exactly this: a required capability declared with no actual technique behind it, until a concrete player (subclass) supplies one.
Step-by-Step Explanation
Step 1
Declare in an abstract class or interface
Write the method signature with the abstract keyword (or as an interface method) and no body, ending in a semicolon.
Step 2
Enclosing class becomes abstract
A class containing an abstract method cannot be instantiated directly and must itself be declared abstract.
Step 3
Subclass provides an implementation
A concrete subclass overrides the abstract method with real, working code.
Step 4
Remaining abstract classes stay non-instantiable
Any subclass that does not implement all inherited abstract methods must itself remain abstract.
What Interviewer Expects
- Correct syntax: abstract keyword, no body, semicolon-terminated
- Understanding that declaring one abstract method makes the class abstract
- Awareness that interface methods are implicitly abstract unless default/static
- A concrete example distinguishing an abstract class/method from a fully concrete one
Common Mistakes
- Trying to instantiate an abstract class directly
- Forgetting to override every inherited abstract method in a concrete subclass
- Confusing abstract methods with final methods (opposite intent — final forbids overriding, abstract requires it)
- Believing abstract methods can have a body in Java (they cannot — that would be a concrete or default method)
Best Answer (HR Friendly)
“An abstract method is a method that's declared but not implemented — it just states the signature, and it lives inside an abstract class or interface. Any concrete class that extends or implements it has to provide the actual implementation, which is how Java forces every subclass to honor a shared contract while still leaving the details up to each specific class.”
Code Example
abstract class Shape {
abstract double area(); // abstract method: signature only, no body
void describe() {
System.out.println("Area is " + area()); // uses the eventual override
}
}
class Rectangle extends Shape {
double width, height;
Rectangle(double w, double h) { this.width = w; this.height = h; }
@Override
double area() { return width * height; } // required implementation
}
// Shape s = new Shape(); // compile error: Shape is abstract
Shape s = new Rectangle(3, 4);
s.describe(); // "Area is 12.0"Follow-up Questions
- What happens if a subclass fails to implement one of several inherited abstract methods?
- How do interface methods differ from abstract-class abstract methods since Java 8 default methods?
- Can an abstract class have a constructor, and why would it need one?
- What is the difference between an abstract method and a pure virtual function in C++?
MCQ Practice
1. An abstract method can be declared in?
Abstract methods live in abstract classes or interfaces, never in a fully concrete class.
2. If a class declares an abstract method, what must be true about the class itself?
A class containing any abstract method must itself be marked abstract and cannot be instantiated directly.
3. What happens if a concrete subclass does not implement an inherited abstract method?
A subclass that leaves an inherited abstract method unimplemented must itself remain abstract, or the compiler reports an error.
Flash Cards
Abstract method in one line? — A method declared with a signature but no body, requiring subclasses to implement it.
Where can it be declared? — In an abstract class or an interface.
Effect on the enclosing class? — The class itself must be declared abstract and cannot be instantiated.
What must a concrete subclass do? — Override and implement every inherited abstract method with real code.