Abstract Method Syntax and Rules
What you'll learn: You'll master the exact syntax requirements for declaring abstract methods, including why they must end with semicolons and cannot have method bodies.
The Core Syntax
An abstract method is a promise: "Subclasses will implement this." Because it's just a promise, it must not have a body—no curly braces, no implementation code. Instead, you end the declaration with a semicolon.
Here's the basic structure:
public abstract returnType methodName(parameters);
Notice three key elements:
- The
abstractkeyword - The method signature (return type, name, parameters)
- A semicolon instead of
{ }
Concrete Examples
public abstract class Shape {
// ✅ Correct: abstract method with semicolon, no body
public abstract double calculateArea();
// ✅ Correct: abstract method with parameters
public abstract void resize(double scaleFactor);
// ❌ WRONG: abstract methods cannot have a body
// public abstract double getPerimeter() { return 0.0; }
// ✅ Correct: non-abstract methods CAN have bodies
public void printInfo() {
System.out.println("This is a shape");
}
}
The Rules
- Must use
abstractkeyword in the method signature - Must end with a semicolon (
;) instead of braces - Cannot have any implementation (no method body at all)
- Can have access modifiers (public, protected, package-private—not private)
- Can declare parameters and return types just like normal methods
- Forces all concrete subclasses to provide an implementation
Think of it like a contract outline: you're defining what must be done, not how to do it. The semicolon signals "implementation required elsewhere."
Key Takeaway: Abstract methods are declared with the abstract keyword, contain only the method signature, and must end with a semicolon—never curly braces—because they define the contract without implementation.