Object-Oriented Programming (OOP) is the foundation of Java. It helps build structured and reusable code.
1. Four Pillars of OOP
- Encapsulation β Protecting data using classes + getters/setters
- Inheritance β Reusing features from parent to child
- Polymorphism β Same method behaving differently
- Abstraction β Showing only important details
2. Simple Example
class Car {
void start() {
System.out.println(“Car starts”);
}
}
class Tesla extends Car {
void start() {
System.out.println(“Tesla starts silently”);
}
}
This is polymorphism through method overriding.
