🧠Object Oriented Programming Principles
Object-Oriented Programming (OOP) is based on four core principles that guide how we design software around real-world objects.
🔑 The Four Core Principles
Encapsulation
Hides internal details and exposes only what’s necessary.Inheritance
Allows a class to inherit methods and properties from another class.Polymorphism
Enables a single interface to operate on different types.Abstraction
Focuses on essential characteristics, hiding implementation.
🎯 Goals of These Principles
- Improve modularity
- Enhance code reuse
- Simplify maintenance
- Align software design with real-world modeling
🧪 Java in Action
interface Vehicle {
void start();
}
class Car implements Vehicle {
public void start() {
System.out.println("Car started");
}
}
This example combines:
- Abstraction (interface)
- Inheritance (implements)
- Polymorphism (Vehicle reference to Car)
- Encapsulation (internal logic hidden)