š§ Abstraction
Abstraction is the process of hiding implementation details and exposing only the essential features. It allows developers to focus on what an object does instead of how it does it.
š§± In Java, Abstraction Is Achieved By:
- Abstract classes (
abstract
keyword) - Interfaces (fully abstract)
š§Ŗ Example Using Abstract Class
abstract class Animal {
abstract void makeSound();
void breathe() {
System.out.println("Breathing...");
}
}
class Dog extends Animal {
void makeSound() {
System.out.println("Bark");
}
}
š§Ŗ Example Using Interface
interface Drawable {
void draw();
}
class Circle implements Drawable {
public void draw() {
System.out.println("Drawing Circle");
}
}
ā Benefits of Abstraction
- Reduces complexity
- Increases reusability
- Enforces standardization (especially through interfaces)
- Helps in designing scalable and modular systems