×

Advanced Coding & Software Engineering Program

Duration: 1 Year (12 Months)

Join our premium 1-year program to master cutting-edge technologies and become an industry-ready Software Engineer!

Course Coverage

  • Languages: C, C++, Java, JavaScript, Python
  • Web Technologies: HTML, CSS, Bootstrap 5, MERN Stack, Full Stack Development
  • Databases: MySQL, MongoDB
  • Data Science Libraries: Pandas, NumPy
  • Development Tools: Visual Studio Code, IntelliJ IDEA, PyCharm, Postman, Git, GitHub
  • Cloud Platforms: Vercel, MongoDB Atlas

Program Highlights

  • Live Classes: Interactive sessions with real-time doubt resolution
  • Hands-On Sessions: Practical coding exercises to build real-world skills
  • Industry Experts: Learn from professionals with years of experience
  • Live Project: Work on real-world projects to apply your skills
  • Get Certificate: Earn a professional certificate upon program completion

Course Fee: Only ₹1020 / month
Limited Period Offer!

Object Oriented Programming (OOP) in C++



Last Updated on: 11th Dec 2025 11:08:33 AM

Introduction to Object Oriented Programming

Object Oriented Programming (OOP) is a programming paradigm that organizes software design around objects and classes rather than functions and logic.
C++ is a powerful object-oriented programming language that allows developers to create real-world models using code.

 

In OOP, programs are built by modeling real-world entities, such as students, cars, bank accounts, or employees, and defining how they interact with each other.

 

Why OOP?

Traditional programming (procedural programming) focuses on functions and logic, while OOP focuses on data and behavior together, making programs:

  • Easier to understand

  • Easier to maintain

  • More scalable

  • More secure

  • Reusable

 

Real-Life Example of OOP

Think about a Car.

  • Data (Attributes):

    • Color

    • Brand

    • Speed

    • Fuel type

  • Behavior (Functions):

    • Start()

    • Stop()

    • Accelerate()

    • Brake()

In OOP, we represent this car as a class, and every real car becomes an object of that class.

 

Key Features of OOP in C++

OOP in C++ is based on six major concepts:

  1. Class

  2. Object

  3. Encapsulation

  4. Abstraction

  5. Inheritance

  6. Polymorphism

 

1. Class

A class is a user-defined blueprint or template used to create objects.
It defines properties (data members) and methods (member functions).

 

Syntax

class ClassName {
    // data members
    // member functions
};

 

Real-Life Example

A Student class:

  • Data: name, roll number, marks

  • Behavior: study(), appearExam()

 

Example Program

#include <iostream>
using namespace std;

class Student {
public:
    string name;
    int roll;

    void display() {
        cout << "Name: " << name << endl;
        cout << "Roll: " << roll << endl;
    }
};

int main() {
    Student s1;
    s1.name = "Rahul";
    s1.roll = 101;
    s1.display();
    return 0;
}

 

2. Object

An object is a real-world instance of a class.
It represents actual values stored in memory.

 

Real-Life Example

  • Class: Car

  • Objects: BMW, Audi, Tesla

 

Each object has its own data values but shares the same structure.

 

3. Encapsulation

Encapsulation means binding data and functions together into a single unit (class) and protecting data from direct access.

 

Encapsulation helps in:

  • Data security

  • Controlled access

  • Better code organization

 

Access Specifiers in C++

Specifier Meaning
 private  Data accessible only within the class
protected Accessible in derived classes
public Accessible from anywhere

 

Real-Life Example

Bank Account:

  • Balance should not be directly modified

  • Only through deposit() or withdraw()

 

Example

class Bank {
private:
    int balance = 1000;

public:
    void deposit(int amt) {
        balance += amt;
    }

    void showBalance() {
        cout << "Balance: " << balance << endl;
    }
};

 

4. Abstraction

Abstraction means hiding internal implementation details and showing only essential features to the user.

 

Real-Life Example

  • Driving a car:

    • You use steering, accelerator, brake

    • You don’t know engine internals

 

Achieved in C++ Using:

  1. Abstract classes

  2. Interfaces (using pure virtual functions)

 

Example

class Vehicle {
public:
    virtual void start() = 0; // pure virtual function
};

class Bike : public Vehicle {
public:
    void start() {
        cout << "Bike started" << endl;
    }
};

 

5. Inheritance

Inheritance allows one class (child class) to inherit properties and behavior from another class (parent class).

 

Benefits

  • Code reusability

  • Faster development

  • Hierarchical classification

 

Types of Inheritance in C++

  1. Single

  2. Multiple

  3. Multilevel

  4. Hierarchical

  5. Hybrid

 

Real-Life Example

  • Parent: Employee

  • Child: Manager

 

Example

class Employee {
public:
    int salary = 30000;
};

class Manager : public Employee {
public:
    int bonus = 10000;
};

 

6. Polymorphism

Polymorphism means one function, many forms.
It allows the same function name to behave differently based on context.

 

Types of Polymorphism

 

1. Compile-time Polymorphism

  • Function Overloading

  • Operator Overloading

 

Example

int add(int a, int b) {
    return a + b;
}

double add(double a, double b) {
    return a + b;
}

 

2. Run-time Polymorphism

  • Achieved using function overriding

  • Requires inheritance and virtual functions

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

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

 

Constructor and Destructor

 

Constructor

  • Special function

  • Automatically called when object is created

  • Same name as class

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

 

Destructor

  • Automatically called when object is destroyed

  • Frees resources

~Demo() {
    cout << "Destructor called" << endl;
}

 

 this  Pointer

this pointer holds the address of the calling object.

class Sample {
    int x;
public:
    void set(int x) {
        this->x = x;
    }
};

 

Static Members

Static members are shared among all objects of the class.

class Counter {
public:
    static int count;
};

 

Advantages of OOP in C++

  • Better code reuse

  • Improved security

  • Easy to manage large programs

  • Real-world modeling

  • Reduced complexity

 

Disadvantages of OOP

  • Higher memory usage

  • Slower execution in some cases

  • Complex for small programs

 

Where OOP is Used?

  • Banking systems

  • E-commerce applications

  • Game development

  • Operating systems

  • Real-world simulations

 

Summary

Object Oriented Programming in C++ provides a structured, secure, and scalable way of writing programs.
By using classes, objects, encapsulation, abstraction, inheritance, and polymorphism, developers can create powerful applications that closely resemble real-world systems.

 

Keep practicing — you're doing amazing!

Happy Coding!    yes

 


Online - Chat Now
Let’s Connect

Inquiry Sent!

Your message has been successfully sent. We'll get back to you soon!

iKeySkills Logo