Abstract Class in Java — Characteristics and Usage
Fast recall
Quick revision
Core answer
abstract and cannot be instantiated directly. It may have constructors, instance and static fields, concrete methods, and abstract methods. A concrete subclass must implement every inherited abstract method. A top-level abstract class can be public or package-private; an abstract nested class may also be protected or private where those modifiers are legal.Whether you know the full feature set of an abstract class and how it differs from an interface.
Thinking an abstract class must have abstract methods, or that it can't have constructors/fields/concrete methods.
Explain that abstract classes shine for shared state + partial implementation (template method pattern), and explicitly confirm you cannot instantiate an abstract class.
Interview-ready guide
Interview answer
The headline characteristic is that you can't instantiate it — new Shape() on an abstract class is a straight compile error. You extend it and instantiate a concrete subclass instead, though you can still hold that subclass in an abstract reference like Shape s = new Circle().
What makes it useful is everything it can contain:
- abstract methods the subclass must implement,
- concrete methods carrying shared logic,
- instance fields,
- and constructors that run through
super().
That mix is why it fits the Template Method pattern — a concrete method fixes the steps and calls an abstract one for the part that varies.
Two things people get wrong. It needs no abstract method at all; the keyword on the class alone blocks new. And it can have constructors — they fire during subclass construction. That's the real line against interfaces: an abstract class carries instance state and constructors, so I use it when related subclasses share data and behavior, and an interface when unrelated classes only need a contract.
Abstract Class in Java — Characteristics and Usage
Direct Answer
An abstract class is declared with abstract and cannot be instantiated directly. It may have constructors, instance and static fields, concrete methods, and abstract methods. A concrete subclass must implement every inherited abstract method. A top-level abstract class can be public or package-private; an abstract nested class may also be protected or private where those modifiers are legal.
Code Example
abstract class Shape {
private final String color; // instance field — shared state
Shape(String color) { // constructor — called via super()
this.color = color;
}
public String getColor() { // concrete method — inherited as-is
return color;
}
public abstract double area(); // abstract method — subclass must implement
public void describe() { // template method — uses the abstract hook
System.out.printf("%s shape, area = %.2f%n", color, area());
}
}
class Circle extends Shape {
private final double radius;
Circle(String color, double radius) {
super(color); // calls Shape's constructor
this.radius = radius;
}
@Override
public double area() {
return Math.PI * radius * radius; // Circle's implementation
}
}
class Rectangle extends Shape {
private final double width, height;
Rectangle(String color, double w, double h) {
super(color);
this.width = w;
this.height = h;
}
@Override
public double area() {
return width * height; // Rectangle's implementation
}
}
public class AbstractClassDemo {
public static void main(String[] args) {
// Shape s = new Shape("red"); // COMPILE ERROR — cannot instantiate abstract class
Shape c = new Circle("red", 5);
Shape r = new Rectangle("blue", 4, 6);
c.describe(); // red shape, area = 78.54
r.describe(); // blue shape, area = 24.00
}
}
Common Mistakes & Pitfalls
- Assuming an abstract class must have at least one abstract method — it doesn't; the
abstractkeyword on the class alone forbidsnew, so a class with only concrete methods can still be abstract. - Believing abstract classes can't have constructors — they can, and they run via
super()to initialize shared fields before the subclass finishes building; assume otherwise and the shared-state model stops making sense. - Trying to instantiate it directly —
new Shape()is a compile error; you instantiate a concrete subclass and may hold it in an abstract reference likeShape s = new Circle(). - Reaching for an abstract class when an interface fits — with no shared state or implementation to inherit, an abstract class burns the single-inheritance slot a subclass might need elsewhere; an interface keeps that slot free.
Check your understanding
Answer these without looking back at the article.
- Can an abstract class have a constructor?
- Can you have an abstract method in a non-abstract class?
- What is the Template Method design pattern?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.