Object-Oriented Programming in C++

📘 C++ 👁 32 views 📅 Dec 22, 2025
⏱ Estimated reading time: 2 min

Object-Oriented Programming is a programming approach that organizes software design around objects rather than functions or logic.


Basic Concepts of OOP

OOP in C++ is based on the following four main principles:

  1. Encapsulation

  2. Abstraction

  3. Inheritance

  4. Polymorphism


1. Class

A class is a blueprint for creating objects.

class Student { public: int roll; string name; };

2. Object

An object is an instance of a class.

Student s1; s1.roll = 1; s1.name = "John";

3. Encapsulation

Binding data and functions together in a single unit (class).

class Account { private: int balance; public: void setBalance(int b) { balance = b; } };
  • Data is protected using access specifiers


4. Abstraction

Hiding internal implementation details and showing only essential features.

Example:

class Shape { public: virtual void draw() = 0; };

5. Inheritance

One class acquires properties of another class.

class Animal { public: void sound() { cout << "Animal sound"; } }; class Dog : public Animal { };

6. Polymorphism

Ability of a function or object to take multiple forms.

Function Overloading

int add(int a, int b); float add(float a, float b);

Function Overriding

class Base { public: virtual void show() { cout << "Base class"; } }; class Derived : public Base { public: void show() { cout << "Derived class"; } };

Access Specifiers

SpecifierDescription
publicAccessible everywhere
privateAccessible within class only
protectedAccessible in derived classes

Constructor

A special function that initializes objects.

class Student { public: Student() { cout << "Constructor called"; } };

Destructor

Used to free resources.

~Student() { cout << "Destructor called"; }

Advantages of OOP

  • Code reusability

  • Better security

  • Easy maintenance

  • Scalability


Conclusion

Object-Oriented Programming in C++ makes programs more organized, reusable, and easier to manage by modeling real-world entities.


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes