Notes – Object Oriented Programming in C++

Object-Oriented Programming (OOP) is a programming approach that organizes code around objects rather than just functions and logic.

C++ supports OOP features that allow building programs that are modular, reusable, and easier to manage.


Why Use OOP?

  • Groups data and behavior together
  • Promotes code reuse through inheritance
  • Makes large codebases easier to maintain and scale
  • Encourages logical structuring of complex systems

Key Concepts of OOP in C++


ConceptDescription
ClassBlueprint for creating objects (data + functions)
ObjectInstance of a class with its own data
EncapsulationBinding data and methods together in one unit
AbstractionHiding internal details and showing only essential features
InheritanceReusing properties and behaviors from another class
PolymorphismAbility to take many forms (function or operator overloading)

Example: Class and Object

#include <iostream>
using namespace std;

class Car {
public:
string brand;
void start() {
cout << brand << " is starting...\n";
}
};

int main() {
Car c1;
c1.brand = "Toyota";
c1.start();
return 0;
}

Benefits of OOP in C++


BenefitImpact
ModularityEasy to divide work into components
ReusabilityWrite once, reuse multiple times
MaintainabilityEasier to fix and update code
ScalabilityEfficiently manage large applications
SecurityControl access to data using access specifiers

Access Specifiers


SpecifierAccess Level
publicAccessible from anywhere
privateAccessible only within the class
protectedAccessible in the class and derived classes