An abstract class gives us a way to define common structure, but sometimes the parent class knows that a particular operation must exist without knowing how that operation should actually work. That is exactly where an abstract method becomes useful.
An abstract method is a method that is declared without a method body. It defines a requirement for subclasses: the method must exist, but the subclass decides how it works.
Think of an abstract method as a promise. The parent class says, “Every concrete subclass must provide this behavior,” while deliberately leaving the implementation to the subclass.
Why Do We Need Abstract Methods?
Consider a payment system. Every payment must be processed, but processing a credit-card payment, UPI payment, and bank-transfer payment can require completely different logic.
A parent class can define the common requirement without guessing the implementation.
abstract class Payment
{
abstract void processPayment();
}
The declaration tells every concrete subclass that it must provide a processPayment() method.
Syntax of an Abstract Method
The basic syntax is simple:
abstract returnType methodName();
Notice the important detail: there is no method body. The declaration ends with a semicolon.
abstract void display(); abstract int calculateSalary();
An abstract method contains a declaration, not an implementation. Its implementation is provided by a suitable subclass.
Abstract Method Example
Suppose an application supports different types of employees. The salary calculation may differ for a permanent employee and a contract employee.
abstract class Employee
{
abstract double calculateSalary();
}
class PermanentEmployee extends Employee
{
@Override
double calculateSalary()
{
return 75000;
}
}
class ContractEmployee extends Employee
{
@Override
double calculateSalary()
{
return 45000;
}
}
class Main
{
public static void main(String[] args)
{
PermanentEmployee permanent = new PermanentEmployee();
ContractEmployee contract = new ContractEmployee();
System.out.println(permanent.calculateSalary());
System.out.println(contract.calculateSalary());
}
}
The parent class defines the common operation, calculateSalary(), but does not know the exact salary-calculation rules. Each subclass supplies its own implementation.
Abstract Method Must Be Implemented
When a concrete class extends an abstract class containing an abstract method, the concrete class must implement that method.
abstract class Animal
{
abstract void sound();
}
class Dog extends Animal
{
@Override
void sound()
{
System.out.println("Dog barks");
}
}
Here, Dog provides the implementation required by the parent class.
If the subclass does not implement the inherited abstract method, the subclass itself must also be declared abstract.
abstract class Animal
{
abstract void sound();
}
abstract class Dog extends Animal
{
// sound() is not implemented here
}
This is valid because Dog is also abstract. A concrete subclass further down the inheritance hierarchy must eventually provide the implementation.
Concrete Subclass Must Implement All Abstract Methods
Suppose an abstract class defines multiple abstract methods.
abstract class Shape
{
abstract void draw();
abstract double calculateArea();
}
A concrete subclass must implement both methods.
class Circle extends Shape
{
@Override
void draw()
{
System.out.println("Drawing circle");
}
@Override
double calculateArea()
{
double radius = 5;
return Math.PI * radius * radius;
}
}
Leaving either method unimplemented would make Circle invalid as a concrete class.
Abstract Method with Parameters
An abstract method can accept parameters just like an ordinary method.
abstract class Notification
{
abstract void send(String message);
}
class EmailNotification extends Notification
{
@Override
void send(String message)
{
System.out.println("Sending email: " + message);
}
}
The parent defines the required operation, while the child determines how the message is delivered.
Abstract Method with a Return Value
An abstract method can also return a value.
abstract class Product
{
abstract double calculatePrice();
}
class Laptop extends Product
{
@Override
double calculatePrice()
{
return 65000;
}
}
The return type in the overriding method must be compatible with the method declared in the parent class.
Abstract Methods and Polymorphism
Abstract methods become especially powerful when combined with polymorphism. You can use an abstract parent reference to work with different concrete objects.
abstract class Payment
{
abstract void pay();
}
class CreditCardPayment extends Payment
{
@Override
void pay()
{
System.out.println("Payment made using credit card");
}
}
class UPIPayment extends Payment
{
@Override
void pay()
{
System.out.println("Payment made using UPI");
}
}
class Main
{
public static void main(String[] args)
{
Payment payment;
payment = new CreditCardPayment();
payment.pay();
payment = new UPIPayment();
payment.pay();
}
}
The variable payment has the parent type, but the actual behavior depends on the object assigned to it. This is runtime polymorphism working together with abstraction.
Abstraction defines what must happen. Polymorphism allows the actual object to decide how it happens at runtime.
Can an Abstract Method Have a Body?
No. An abstract method does not provide an implementation body.
abstract class Vehicle
{
abstract void start()
{
System.out.println("Starting");
}
}
The above declaration is invalid because an abstract method cannot contain a method body.
If a method needs a common implementation, declare it as a normal concrete method instead.
abstract class Vehicle
{
void stop()
{
System.out.println("Vehicle stopped");
}
abstract void start();
}
This combination is one of the most useful features of abstract classes: one method can provide shared behavior while another forces subclasses to provide specialized behavior.
Can a Normal Class Contain an Abstract Method?
No. If a class contains an abstract method, the class itself must be declared abstract.
class Vehicle
{
abstract void start();
}
The declaration above is invalid. It should be written as:
abstract class Vehicle
{
abstract void start();
}
Abstract Methods Cannot Be Private
An abstract method must be available to subclasses for implementation. A private method is accessible only inside its declaring class, so making an abstract method private creates a contradiction.
abstract class Vehicle
{
private abstract void start(); // Invalid
}
The method must have an access level that allows the subclass to provide its implementation.
Abstract Methods Cannot Be Final
The final keyword means that a method cannot be overridden. An abstract method, on the other hand, requires a subclass to override it. These two requirements conflict.
abstract class Vehicle
{
final abstract void start(); // Invalid
}
abstract means “must be implemented by a subclass,” while final means “cannot be overridden.” Therefore, an abstract method cannot be final.
Abstract Methods Cannot Be Static
Static methods belong to the class rather than an object and are not overridden through runtime polymorphism. Abstract methods depend on subclass implementation, so an abstract method cannot be declared static.
abstract class Vehicle
{
static abstract void start(); // Invalid
}
Using @Override with Abstract Methods
When implementing an abstract method in a subclass, using the @Override annotation is strongly recommended.
abstract class Employee
{
abstract void work();
}
class Developer extends Employee
{
@Override
void work()
{
System.out.println("Developer writes code");
}
}
The annotation tells the compiler that the method is intended to override a parent method. If you accidentally change the method signature, the compiler can detect the mistake.
Method Signature Must Match
When implementing an abstract method, the subclass must use a compatible method signature.
abstract class Animal
{
abstract void sound();
}
class Dog extends Animal
{
@Override
void sound()
{
System.out.println("Bark");
}
}
Changing the parameter list creates a different method rather than implementing the original abstract method.
abstract class Animal
{
abstract void sound();
}
class Dog extends Animal
{
void sound(String type)
{
System.out.println(type);
}
}
The sound(String type) method does not implement sound(). Therefore, Dog would still need to implement the original abstract method to become concrete.
Abstract Method in a Multi-Level Inheritance Hierarchy
Abstract methods can remain unimplemented across several levels of inheritance.
abstract class Animal
{
abstract void sound();
}
abstract class Mammal extends Animal
{
// sound() is still not implemented
}
class Dog extends Mammal
{
@Override
void sound()
{
System.out.println("Dog barks");
}
}
Here, Animal declares the requirement, Mammal keeps the requirement abstract, and Dog finally provides the implementation.
Common Beginner Mistakes
- Writing a method body for an abstract method.
- Declaring an abstract method inside a non-abstract class.
- Trying to make an abstract method private, static, or final.
- Changing the method signature while attempting to implement the abstract method.
- Forgetting to implement all inherited abstract methods in a concrete subclass.
- Assuming abstract methods can be called by creating an object of the abstract parent class.
Best Practices
- Use abstract methods when the parent class can define the required behavior but cannot provide a meaningful common implementation.
- Use descriptive method names so subclasses clearly understand the responsibility they must implement.
- Use @Override when implementing abstract methods.
- Keep the abstract contract focused; avoid forcing subclasses to implement unrelated operations.
- Combine abstract methods with concrete methods when some behavior is common and other behavior varies between subclasses.
Interview Insights
Question: What is an abstract method?
Answer: An abstract method is a method declared without an implementation. It defines behavior that a concrete subclass must implement.
Question: Can an abstract method have a body?
Answer: No. An abstract method only declares the method signature and does not contain an implementation body.
Question: What happens if a concrete subclass does not implement an abstract method?
Answer: The subclass must itself be declared abstract; otherwise, the compiler reports an error.
Question: Can an abstract method be private, final, or static?
Answer: No. An abstract method must be implementable through inheritance, which conflicts with the semantics of private, final, and static methods.
Quick Revision
| Concept | Key Point |
|---|---|
| Abstract method | A method declared without an implementation. |
| Method body | Not allowed in an abstract method. |
| Concrete subclass | Must implement all inherited abstract methods. |
| Abstract subclass | May inherit abstract methods without implementing them. |
| @Override | Recommended when implementing an abstract method. |
| Private | An abstract method cannot be private. |
| Final | An abstract method cannot be final. |
| Static | An abstract method cannot be static. |
Final Takeaway
An abstract method is a contract between a parent class and its subclasses. The parent defines what operation must exist, while each concrete subclass defines how that operation should work. This simple separation is one of the foundations of abstraction and becomes especially powerful when combined with inheritance and runtime polymorphism.
