🧠 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

  1. Encapsulation
    Hides internal details and exposes only what’s necessary.

  2. Inheritance
    Allows a class to inherit methods and properties from another class.

  3. Polymorphism
    Enables a single interface to operate on different types.

  4. 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)