Object-Oriented Programming (OOP) — Midterm Notes
1. Introduction to OOP
A programming paradigm that models software using classes and objects to improve modularity,
reuse, and maintainability.
Key Points
• Encapsulation, Inheritance, Polymorphism, Abstraction
• Models real-world entities
• Supports code reuse and scalability
2. Class
A user-defined type that groups data members and member functions.
Example (C++)
class Car {
public:
string color;
int speed;
void start(){ cout << "Car started"; }
};
3. Object
An instance of a class used to access its members.
Example (C++)
Car c1;
[Link] = "Red";
[Link] = 120;
[Link]();
4. Derived Classes (Inheritance)
Mechanism where a class acquires properties and behavior of another class.
Syntax (C++)
class Parent { public: void show(){ cout << "Parent"; } };
class Child : public Parent { public: void display(){ cout << "Child"; } };
Usage
Child c;
[Link]();
[Link]();
5. Constructor and Overloading
A special member function invoked automatically when an object is created to initialize data
members.
Example (C++)
class Car {
public:
Car(){ cout << "Default"; }
Car(string c){ cout << c; }
};
6. Destructor
A special member function invoked automatically when an object goes out of scope to release
resources.
Syntax (C++)
class Car {
public:
~Car(){ cout << "Destroyed"; }
};