
Simplifying OOP in Java: Abstraction
A simple introduction to abstraction in Java, showing how abstract classes and abstract methods help define general ideas without forcing every detail immediately.
Day 8: Abstraction
As OOP grows, not every class needs to define every detail by itself.
Sometimes we want a parent class to describe a general idea, while the child classes handle the exact behavior.
That is the idea behind abstraction.
In Java, abstraction is often done using an abstract class and abstract methods.
abstract class Vehicle {
abstract void move();
}
class Car extends Vehicle {
@Override
void move() {
System.out.println("Car is moving");
}
}In this example, Vehicle defines the idea of a move() method, but it does not say exactly how that movement should happen.
The Car class completes that behavior by giving its own implementation.
This is what makes abstraction useful. It lets us focus on the main idea first, while leaving the specific details to the classes that actually need them.