Member-only story

Abstract Method vs Concrete Method in Java: Unleashing the Power of Abstraction

Naveen Metta
5 min readJun 25, 2023

--

Introduction:

In the world of Java programming, abstract methods and concrete methods are two powerful concepts that enable developers to create flexible, extensible, and maintainable code structures. In this article, we will delve into the differences between these two concepts, explore practical examples of their usage, and understand the benefits they bring to Java programming.

Understanding Abstract Methods:

Abstract methods serve as blueprints for derived classes to provide their own implementation. They lack implementation details and are defined using the abstract keyword. Abstract methods are typically found within abstract classes or interfaces.
Let’s consider an example of an abstract class Animal with an abstract method makeSound():

abstract class Animal {
abstract void makeSound();
}

class Cat extends Animal {
void makeSound() {
System.out.println("Meow!");
}
}

class Dog extends Animal {
void makeSound() {
System.out.println("Woof!");
}
}

public class Main {
public static void main(String[] args) {
Animal cat = new Cat();
cat.makeSound(); // Output: Meow!

Animal dog = new Dog();
dog.makeSound(); // Output: Woof!
}
}

In the above code, the Animal class defines the abstract method makeSound(). The derived classes Cat and Dog override this method, providing their…

--

--

Naveen Metta
Naveen Metta

Written by Naveen Metta

I'm a Full Stack Developer with 3+ years of experience. feel free to reach out for any help : mettanaveen701@gmail.com

No responses yet