Abstract and final methods represent contrasting concepts in object-
oriented programming, particularly in languages like Java.
Abstract Methods:
• An abstract method is a method declared without an implementation (a
method body).
• It serves as a placeholder for a method that subclasses are required to
implement.
• A class containing abstract methods must be declared as an abstract class.
• Abstract methods promote polymorphism and define a common interface
that subclasses must adhere to.
• They are used when a superclass cannot provide a meaningful default
implementation for a method, but all subclasses are expected to have that
method.
Example of an Abstract Method (Java
abstract class Shape {
abstract void draw(); // Abstract method - no implementation here
class Circle extends Shape {
void draw() {
System.out.println("Drawing a circle");
Final Methods:
• A final method is a method that cannot be overridden by any subclass.
• It is declared using the final keyword.
• Final methods are used to prevent subclasses from altering or extending the
behavior of a method.
• They ensure that a specific implementation of a method remains consistent
across the class hierarchy.
Example of a Final Method (Java):
class Car {
final void startEngine() {
System.out.println("Engine started");
class SportsCar extends Car {
// Cannot override startEngine() here, it's final
// void startEngine() { ... } // This would cause a compile-time error
Key Differences:
• Implementation:
Abstract methods have no implementation and must be implemented by
subclasses, while final methods have a complete implementation and
cannot be overridden.
• Overriding:
Abstract methods require overriding, while final methods prohibit overriding.
• Class Type:
Abstract methods can only exist within abstract classes, whereas final
methods can exist in any class (abstract or concrete).