☕ *Java OOP (Object-Oriented Programming)
*OOP means writing code using * real-life objects* like *car, person, animal*, etc.
Let’s break it down:
1️⃣ *Class & Object* –
*Class* = design or blueprint (like a car model). – *Object* = real thing (your specific car).*Example:*“`javaclass Car { String color; void drive() { System.out.println(“Driving”); }}Car myCar = new Car(); // object createdmyCar.drive(); // prints: Driving“`
2️⃣ *Constructor*
– Special method that runs when an object is created. *It sets values inside the object.*“`javaclass Person { String name; Person(String n) { name = n; }}Person p = new Person(“Alice”);“`
3️⃣ *Inheritance*
– One class *borrows* from another. – Example: Dog is an Animal.“`javaclass Animal { void sound() { System.out.println(“Animal sound”); }}class Dog extends Animal { void bark() { System.out.println(“Barking”); }}“`
4️⃣ *Polymorphism*
– Same word, different behavior. – Example: A shape can be a circle or square.“`javaclass Shape { void draw() { System.out.println(“Drawing shape”); }}class Circle extends Shape { void draw() { System.out.println(“Drawing circle”); }}“`
5️⃣ *Encapsulation*
– Hide data inside the class & give controlled access.“`javaclass Bank { private int balance = 1000; public int getBalance() { return balance; }}“`
6️⃣ *Abstraction*
– Only show *important* things, hide the rest.“`javaabstract class Animal { abstract void makeSound(); // no body, just plan}“`🧠
*OOP helps you write cleaner, reusable, real-world-like code.*
*React ❤️ for more!*
