OOPS Notes (Object-Oriented Programming System)
1. What is OOPS?
OOPS is a programming paradigm based on the concept of objects.
It helps organize code in a modular, reusable, and efficient manner.
---
2. Important Terms
🔹 Class
A blueprint/template for creating objects.
Example: A Car class defines what a car is.
🔹 Object
An instance of a class.
Example: Car myCar = new Car();
🔹 Attribute (Data Members)
Variables inside a class.
Example: color, speed.
🔹 Method (Member Functions)
Functions defined inside a class that operate on object data.
---
3. Four Pillars of OOPS
1️⃣ Encapsulation
Binding data + methods into one unit (class).
Protects data using private access.
Example: Getters and setters.
2️⃣ Inheritance
One class acquiring properties of another.
Types of inheritance:
Single
Multilevel
Hierarchical
Multiple (not in Java)
Hybrid
3️⃣ Polymorphism
Same function name, different behavior.
Types:
Compile-time (Method Overloading)
Runtime (Method Overriding)
4️⃣ Abstraction
Hiding internal details and showing essential features.
Achieved using abstract classes or interfaces.
---
4. Advantages of OOPS
Reusability
Security
Better maintainability
Real-world modeling
Code flexibility and scalability
---
5. OOPS in Real Life
Example objects:
Car → color, speed, start(), stop()
Bank Account → balance, deposit(), withdraw()
---
6. Simple Example (Java)
class Car {
String brand;
int speed;
Car(String brand, int speed) {
[Link] = brand;
[Link] = speed;
}
void drive() {
[Link](brand + " is driving at " + speed + " km/h");
}
}
public class Main {
public static void main(String[] args) {
Car c1 = new Car("BMW", 120);
[Link]();
}
}
---
7. Simple Example (Python)
class Car:
def __init__(self, brand, color):
[Link] = brand
[Link] = color
def show(self):
print("Brand:", [Link], "| Color:", [Link])
car1 = Car("Audi", "Red")
[Link]()