Abstract Methods: Signature Without Body
What you'll learn: How to declare abstract methods that define a contract without implementation, forcing subclasses to provide the actual behavior.
The Core Idea
An abstract method is a method declaration with no body—just a signature followed by a semicolon. It's like writing a promise: "Any concrete subclass must implement this method." You use the abstract keyword and omit the curly braces entirely.
Think of it as a blueprint requirement: if you're designing a Vehicle class and declare an abstract method start(), you're saying "every vehicle must be able to start, but how it starts depends on the specific type of vehicle." A Car starts with an ignition, a Boat with a motor pull-cord—the abstract method enforces that all vehicles provide their own start() behavior.
Syntax
public abstract class Vehicle {
// Abstract method: signature only, no body
public abstract void start();
public abstract int getMaxSpeed();
}
Notice there are no curly braces {} and the declaration ends with a semicolon ;.
The Contract
When a concrete class extends Vehicle, it must override and implement all abstract methods, or it too must be declared abstract:
public class Car extends Vehicle {
@Override
public void start() {
System.out.println("Turn the ignition key");
}
@Override
public int getMaxSpeed() {
return 180;
}
}
The compiler enforces this contract—you cannot instantiate a class with unimplemented abstract methods.
Why Use Abstract Methods?
They let you define a common interface in a superclass while deferring specific implementation details to subclasses. This ensures consistency across your hierarchy while allowing flexibility.
Key Takeaway: Abstract methods declare what must be done without specifying how, creating a binding contract that all concrete subclasses must fulfill through overriding.