Skip to main content
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 1
Unit-II Classes and Objects
CO/BTL
Level
CO2- To develop object-oriented programs using classes, objects, constructors,
member functions, and dynamic memory management. (BTL Level-APPLY)
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PSO1 PSO2 PSO3
CO1 3 3 2 - 2 - - - - - - 2 - 2
Unit Content
Class and object concepts ,Access specifiers ,Member functions ,Array of objects ,Objects as
function arguments, Constructors and destructors ,Types of constructors ,Static members and
static member functions, Friend functions and friend classes ,This pointer, Dynamic memory
allocation using new and delete
2.1 Class and Object Concepts
2.1.1 Introduction to Classes and Objects
Object-Oriented Programming (OOP) is a programming paradigm that organizes software by combining
data and the functions that operate on that data into a single unit called an object. Unlike procedural
programming, where data and functions are separate, OOP focuses on representing real-world entities as
objects. C++ is one of the most popular object-oriented programming languages because it provides
powerful features such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction.
The two fundamental concepts of OOP are class and object. A class acts as a blueprint or template that
defines the properties (data members) and behaviors (member functions) of an object. An object is an
instance of a class that occupies memory and performs operations defined in the class.
For example, a Student class may define properties such as Roll Number, Name, and Marks, along with
functions such as acceptData() and displayData(). Each student in a college represents a separate object
created from the Student class.
Using classes and objects makes software modular, reusable, secure, and easier to maintain. They also
simplify the development of large-scale applications by organizing related data and functions together.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 2
Objectives of Classes and Objects:
The primary objectives of using classes and objects are:
 To represent real-world entities in software.
 To combine data and functions into a single unit.
 To improve code reusability.
 To provide data security through encapsulation.
 To simplify software maintenance.
 To support modular programming.
 To improve program readability.
 To reduce code duplication.
Features of Classes and Objects:
 Represent real-world entities.
 Promote modular programming.
 Improve code organization.
 Support encapsulation.
 Enable data hiding.
 Provide code reusability.
 Simplify debugging.
 Improve maintainability.
 Form the foundation of all OOP concepts.
Need for Classes and Objects:
Procedural programming becomes difficult to manage as software size increases. Global variables can be
modified by any function, leading to security and maintenance issues. Classes solve these problems by
grouping related data and functions into a single unit.
Advantages include:
 Better organization of code
 Reduced complexity
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 3
 Improved security
 Higher reusability
 Easier maintenance
 Better scalability
Real-World Analogy:
Consider a Car.
The blueprint prepared by the manufacturer specifies:
 Model
 Color
 Engine Capacity
 Fuel Type
 Maximum Speed
This blueprint is equivalent to a Class.
Every manufactured car based on this blueprint is an Object.
Example:
Class: Car
Objects:
 Car1 (Red Honda City)
 Car2 (White Honda City)
 Car3 (Black Honda City)
Although each car has different values, they all belong to the same class.
Similarly, in C++, one class can create many objects.
Example:
A Bank Account class may contain:
Data Members
 Account Number
 Customer Name
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 4
 Balance
Member Functions
 Deposit()
 Withdraw()
 Display()
Each customer's account is a different object of the Bank Account class.
Advantages of Using Classes and Objects:
 Code Reusability
 Data Security
 Easy Maintenance
 Modular Programming
 Improved Flexibility
 Better Code Organization
 Simplified Debugging
 Supports Large Applications
Limitations:
 Slightly higher memory usage than procedural programming.
 Initial program design requires more planning.
 Small programs may become comparatively lengthy.
 Learning OOP concepts requires additional effort.
Applications:
Classes and objects are widely used in:
 Banking Systems
 Student Management Systems
 Hospital Management Systems
 Inventory Systems
 Library Management Systems
 E-Commerce Applications
 Mobile Applications
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 5
 Game Development
 Artificial Intelligence
 Internet of Things (IoT)
2.1.2 Class
Introduction
A class is one of the fundamental concepts of Object-Oriented Programming (OOP). It serves as a blueprint
or template for creating objects. A class defines the structure (data) and behavior (functions) that all objects
of that class will possess. It does not occupy memory until one or more objects are created.
In C++, a class groups related data members and member functions into a single logical unit, thereby
improving code organization, security, and reusability. By using classes, programmers can model real-world
entities efficiently and build modular software applications.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 6
Definition:
A class is a user-defined data type in C++ that encapsulates data members (variables) and member functions
(methods) into a single unit. It specifies the properties and behaviors that objects created from the class will
have.
Syntax of a Class:
class ClassName
{
private:
// Data members
public:
// Member functions
protected:
// Protected members
};
General Structure of a Class:
A class consists of the following components:
 Class keyword
 Class name
 Access specifiers
 Data members
 Member functions
The class definition ends with a semicolon (;).
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 7
Components of a Class:
1. Class Keyword
The keyword class is used to declare a class in C++.
Example:
class Student
{
};
2. Class Name
The class name uniquely identifies the class and follows the rules for identifiers in C++.
Example:
class Employee
{
};
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 8
3. Data Members
Data members are variables declared inside a class. They represent the attributes or properties of an object.
Example:
int rollNo;
string name;
float marks;
4. Member Functions
Member functions define the operations that can be performed on the objects of the class.
Example:
void acceptData();
void displayData();
5. Access Specifiers
Access specifiers determine the accessibility of class members.
The three access specifiers are:
 Private
 Public
 Protected
Example of a Class:
class Student
{
private:
int rollNo;
string name;
float marks;
public:
void acceptData();
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 9
void displayData();
};
In this example:
 Student is the class name.
 rollNo, name, and marks are data members.
 acceptData() and displayData() are member functions.
Characteristics of a Class:
 It is a user-defined data type.
 It acts as a blueprint for creating objects.
 It combines data and functions into one unit.
 It supports data hiding through access specifiers.
 It improves modularity and code organization.
 It enables code reusability.
 Multiple objects can be created from a single class.
 Memory is not allocated when a class is declared.
Working of a Class:
The working of a class involves the following steps:
1. Define a class using the class keyword.
2. Declare data members and member functions.
3. Create one or more objects of the class.
4. Access data members and member functions using objects.
5. Execute operations defined by the member functions.
Advantages of a Class:
 Supports Object-Oriented Programming.
 Provides better code organization.
 Improves code reusability.
 Enhances data security.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 10
 Supports modular programming.
 Simplifies debugging.
 Makes software maintenance easier.
 Reduces program complexity.
Limitations of a Class:
 Requires proper planning during software design.
 Slightly increases program complexity for very small applications.
 Improper class design may lead to inefficient code.
 Learning object-oriented concepts requires additional effort.
Real-World Example:
Consider a Student in a college.
The common characteristics of every student are:
 Roll Number
 Name
 Department
 Marks
Common operations performed are:
 Accept student details
 Display student details
 Calculate percentage
These common properties and operations are grouped together in a Student class. Every individual student
becomes an object of this class.
2.1.3 Object
Introduction:
An object is an instance of a class. While a class defines the blueprint or template, an object represents the
actual implementation of that blueprint. An object occupies memory and allows the programmer to access
the data members and member functions defined in the class.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 11
Every object has its own copy of data members but shares the member functions defined in the class.
Multiple objects can be created from a single class, and each object can have different values for its data
members.
For example, if Student is a class, then student1, student2, and student3 are different objects of the
Student class.
Definition:
An object is a runtime instance of a class that contains its own copy of the data members and can access the
member functions defined in the class.
Syntax of Creating an Object:
ClassName objectName;
Example:
Student s1;
Employee emp1;
Car car1;
Here,
 Student, Employee, and Car are class names.
 s1, emp1, and car1 are objects.
Declaring Multiple Objects:
Multiple objects can be created in a single statement.
Syntax:
ClassName obj1, obj2, obj3;
Example:
Student s1, s2, s3;
Each object has its own independent data.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 12
Creating Objects:
The following steps are involved in creating an object.
Step 1:
Define the class.
class Student
{
public:
int rollNo;
string name;
};
Step 2:
Create an object.
Student s1;
Memory is allocated only after this statement is executed.
Step 3:
Access members using the dot operator.
s1.rollNo = 101;
s1.name = "Rahul";
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 13
Memory Allocation for Objects:
A class itself does not occupy memory.
Memory is allocated only when an object is created.
Consider the following class.
class Student
{
public:
int rollNo;
float marks;
};
When an object is created,
Student s1;
Memory is allocated for:
 rollNo
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 14
 marks
If another object is created,
Student s2;
A separate memory block is allocated for s2.
Thus,
 s1.rollNo
 s2.rollNo
are stored at different memory locations.
Accessing Object Members:
The dot (.) operator is used to access the members of an object.
Syntax:
objectName.dataMember;
objectName.memberFunction();
Example:
Student s1;
s1.rollNo = 15;
s1.name = "Amit";
s1.display();
Example Program:
#include<iostream>
using namespace std;
// Class definition
class Student
{
public:
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 15
int rollNo;
string name;
// Member function
void display()
{
cout << "Roll Number : " << rollNo << endl;
cout << "Name : " << name << endl;
}
};
int main()
{
// Creating object
Student s1;
// Accessing data members
s1.rollNo = 101;
s1.name = "Rahul";
// Calling member function
s1.display();
return 0;
}
Output:
Roll Number: 101
Name : Rahul
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 16
Characteristics of Objects:
 An object is an instance of a class.
 Every object occupies memory.
 Each object contains its own copy of data members.
 Member functions are shared among all objects.
 Objects interact using member functions.
 Multiple objects can be created from one class.
 Objects can communicate with each other by passing messages (function calls).
Advantages of Objects:
 Represents real-world entities.
 Supports modular programming.
 Enables code reuse.
 Improves readability.
 Simplifies debugging.
 Makes software scalable.
 Supports data encapsulation.
Limitations:
 Creating too many objects increases memory usage.
 Improper object design may reduce efficiency.
 Large numbers of objects may increase execution time.
Real-World Example:
Consider a Student class.
Different students in a classroom are different objects.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 17
Class Objects
Student Rahul
Student Priya
Student Sneha
Student Amit
Each student has different values for:
 Roll Number
 Name
 Marks
but all follow the same class definition.
Another example is a Car class.
Objects:
 Honda City
 Hyundai Verna
 Tata Nexon
 Maruti Baleno
Each car has its own color, registration number, and owner while sharing the same general properties
defined in the class.
2.1.4 Difference between Class and Object
Although the terms class and object are closely related, they have different meanings in Object-Oriented
Programming. A class is a blueprint that defines the structure and behavior of objects, whereas an object is a
real instance of that blueprint that occupies memory and performs operations.
A class serves as a logical description of an entity, while an object represents the physical implementation of
that entity during program execution.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 18
Comparison between Class and Object:
Class Object
A class is a blueprint or template. An object is an instance of a class.
It is a user-defined data type. It is a variable of class type.
A class does not occupy memory. An object occupies memory.
A class defines data members and member functions. An object contains actual values of data members.
A class is declared using the class keyword. An object is created using the class name.
A class can create multiple objects. An object belongs to only one class.
Member functions are defined in the class. Member functions are accessed through objects.
A class is created only once. Multiple objects can be created from one class.
Example:
Consider the following class:
class Student
{
public:
int rollNo;
string name;
};
Objects of the class:
Student s1;
Student s2;
Student s3;
Here,
 Student is the class.
 s1, s2, and s3 are objects.
Each object stores different values.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 19
For example:
Object Roll Number Name
s1 101 Rahul
s2 102 Priya
s3 103 Amit
Although all three objects belong to the same class, each has its own independent data.
Real-World Example:
Consider the class Car.
The class defines common properties:
 Model
 Color
 Engine Capacity
 Fuel Type
Objects created from this class may be:
Class Objects
Car Honda City
Car Hyundai Verna
Car Tata Nexon
Each car is different, but all are created using the same blueprint.
Similarly,
Class Objects
Student Rahul
Student Priya
Student Sneha
The class specifies the common structure, while objects contain actual information.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 20
Advantages of Using Classes and Objects Together:
 Improves modularity.
 Reduces code duplication.
 Enhances data security.
 Makes software easier to maintain.
 Allows creation of multiple objects from a single class.
 Supports real-world modeling.
 Improves program readability and scalability.
2.1.5 Declaration and Definition of a Class
A class must be declared and defined before objects can be created. The class declaration specifies the
name of the class along with its data members and member functions. Once the class is defined, it acts as a
blueprint for creating objects.
In C++, the declaration and definition of a class are usually written together. However, member functions
can be defined either inside the class or outside the class using the scope resolution operator (::).
Class Declaration:
A class is declared using the class keyword followed by the class name.
Syntax:
class ClassName
{
// Data members
// Member functions
};
Example:
class Student
{
public:
int rollNo;
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 21
string name;
void display();
};
In this example:
 Student is the class name.
 rollNo and name are data members.
 display() is the member function declaration.
Class Definition:
The class definition contains all the members of the class. It specifies the structure and behavior of the class.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 22
Example:
class Employee
{
private:
int empId;
string empName;
float salary;
public:
void acceptData()
{
cout << "Enter Employee ID: ";
cin >> empId;
cout << "Enter Employee Name: ";
cin >> empName;
cout << "Enter Salary: ";
cin >> salary;
}
void displayData()
{
cout << "nEmployee ID : " << empId << endl;
cout << "Employee Name : " << empName << endl;
cout << "Salary : " << salary << endl;
}
};
The above class contains:
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 23
 Three data members
 Two member functions
 Two access specifiers
Complete Program:
#include<iostream>
using namespace std;
// Class declaration and definition
class Student
{
public:
int rollNo;
string name;
void display()
{
cout << "Roll Number : " << rollNo << endl;
cout << "Name : " << name << endl;
}
};
int main()
{
// Creating object
Student s1;
// Initializing data members
s1.rollNo = 101;
s1.name = "Rahul";
// Calling member function
s1.display();
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 24
return 0;
}
Output:
Roll Number: 101
Name : Rahul
Rules for Declaring a Class:
 The class name must follow the rules of identifiers.
 A class definition must end with a semicolon (;).
 Data members and member functions are enclosed within curly braces { }.
 Access specifiers determine the accessibility of members.
 Objects cannot be created before the class is declared.
Characteristics:
 A class is declared using the class keyword.
 The class definition specifies both data and functions.
 Member functions may be defined inside or outside the class.
 A class serves as a blueprint for creating objects.
 Memory is allocated only when objects are created.
Advantages:
 Improves code organization.
 Supports modular programming.
 Enables code reuse.
 Improves readability.
 Provides data security using access specifiers.
 Simplifies software maintenance.
Real-World Example:
Consider a Library Management System.
A Book class may contain:
Data Members
 Book ID
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 25
 Title
 Author
 Price
Member Functions
 Issue Book
 Return Book
 Display Book Details
Every book in the library is created as an object of the Book class.
2.1.6 Creating Objects
After defining a class, the next step is to create objects. An object is a variable of a class type that occupies
memory and allows access to the data members and member functions of the class. A class can create any
number of objects, and each object maintains its own copy of the data members.
Objects are declared in the same way as variables of built-in data types, except that the data type is the class
name.
Syntax:
ClassName objectName;
Creating a Single Object:
The following statement creates a single object of the class.
Student s1;
Here,
 Student is the class name.
 s1 is the object.
When this statement is executed, memory is allocated for all the data members of s1.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 26
Creating Multiple Objects:
Multiple objects of the same class can also be created in a single statement.
Syntax:
ClassName obj1, obj2, obj3;
Example:
Student s1, s2, s3;
In this example, three independent objects are created.
Each object stores its own data.
Working of Object Creation
The process of creating an object can be summarized as follows:
1. Define the class.
2. Declare an object using the class name.
3. Memory is allocated for the object.
4. Initialize the object's data members.
5. Access member functions using the object.
Accessing Object Members:
The dot operator (.) is used to access the members of an object.
Syntax:
objectName.dataMember;
objectName.memberFunction();
Example:
Student s1;
s1.rollNo = 101;
s1.name = "Rahul";
s1.display();
Here,
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 27
 rollNo and name are accessed using the dot operator.
 display() is called through the object.
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
void display()
{
cout << "Roll Number : " << rollNo << endl;
cout << "Name : " << name << endl;
}
};
int main()
{
// Creating objects
Student s1, s2;
// Initializing object s1
s1.rollNo = 101;
s1.name = "Rahul";
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 28
// Initializing object s2
s2.rollNo = 102;
s2.name = "Priya";
// Displaying details
cout << "Student 1 Detailsn";
s1.display();
cout << "nStudent 2 Detailsn";
s2.display();
return 0;
}
Output:
Student 1 Details
Roll Number : 101
Name : Rahul
Student 2 Details
Roll Number : 102
Name : Priya
Memory Allocation during Object Creation:
When objects are created, memory is allocated separately for each object.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 29
Example:
Student s1;
Student s2;
Memory Layout
Object s1
-----------
rollNo
name
Object s2
-----------
rollNo
name
Although both objects belong to the same class, they store different values in separate memory locations.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 30
Characteristics of Object Creation:
 Objects are variables of class type.
 Memory is allocated only after object creation.
 Each object has its own copy of data members.
 Member functions are common to all objects.
 Multiple objects can be created from one class.
 Objects can access only the members permitted by access specifiers.
Advantages:
 Represents real-world entities.
 Allows multiple instances of a class.
 Supports modular programming.
 Improves code reusability.
 Simplifies software development.
 Enables independent data storage for each object.
Real-World Example:
Consider a Bank Account class.
Different customers have different bank accounts.
Class Objects
BankAccount Account1
BankAccount Account2
BankAccount Account3
Each account contains different values such as:
 Account Number
 Customer Name
 Balance
However, all accounts use the same member functions such as:
 Deposit()
 Withdraw()
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 31
 DisplayBalance()
2.1.7 Accessing Class Members
After creating an object, the next step is to access its data members and member functions. In C++, the dot
(.) operator is used to access public members of an object. The dot operator establishes the relationship
between an object and its members.
Only the public members of a class can be accessed directly using an object. Private and protected members
cannot be accessed directly from outside the class.
Accessing Data Members:
Data members store the attributes of an object. They can be assigned values or read using the dot operator.
Syntax:
objectName.dataMember;
Example:
Student s1;
s1.rollNo = 101;
s1.name = "Rahul";
s1.marks = 88.50;
In this example:
 rollNo
 name
 marks
are data members accessed through the object s1.
Accessing Member Functions:
Member functions perform operations on the data members of an object.
Syntax:
objectName.memberFunction();
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 32
Example:
Student s1;
s1.acceptData();
s1.displayData();
Here,
 acceptData() accepts student information.
 displayData() displays student information.
Complete Program:
#include<iostream>
using namespace std;
class Student
{
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 33
public:
int rollNo;
string name;
float marks;
void display()
{
cout << "Roll Number : " << rollNo << endl;
cout << "Name : " << name << endl;
cout << "Marks : " << marks << endl;
}
};
int main()
{
Student s1;
// Accessing data members
s1.rollNo = 101;
s1.name = "Rahul";
s1.marks = 89.5;
// Accessing member function
s1.display();
return 0;
}
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 34
Output:
Roll Number : 101
Name : Rahul
Marks : 89.5
Accessing Multiple Objects:
Each object accesses its own members independently.
Student s1, s2;
s1.rollNo = 101;
s1.name = "Rahul";
s2.rollNo = 102;
s2.name = "Priya";
Although both objects belong to the same class, their data is stored separately.
Rules for Accessing Members:
 Only public members can be accessed directly.
 The dot (.) operator is used with objects.
 Member functions can access both public and private data members.
 Every object accesses its own copy of the data members.
 Multiple objects can call the same member function.
Characteristics:
 Uses the dot (.) operator.
 Access is performed through objects.
 Public members are directly accessible.
 Private members are accessed indirectly through member functions.
 Each object stores its own data values.
 Member functions are shared among all objects.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 35
Advantages:
 Provides controlled access to object data.
 Improves data security through access specifiers.
 Makes programs modular and organized.
 Simplifies code readability.
 Supports encapsulation.
Real-World Example:
Consider an Employee class.
Different employees can access their own information.
Object Employee Name Employee ID
emp1 Amit 201
emp2 Sneha 202
emp3 Rahul 203
Each object accesses its own data members using the dot operator.
Example:
emp1.display();
emp2.display();
emp3.display();
2.1.8 Memory Representation of Objects
Memory allocation is an important concept in Object-Oriented Programming. A class itself does not occupy
memory because it is only a blueprint. Memory is allocated only when objects are created. Each object
created from a class receives its own separate memory for storing the values of its data members.
Although every object has its own copy of the data members, the member functions are shared among all
objects. This reduces memory consumption and improves program efficiency.
Memory Allocation in Objects:
When an object is created, memory is allocated only for the data members declared in the class.
Consider the following class.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 36
class Student
{
public:
int rollNo;
string name;
float marks;
void display()
{
cout << rollNo << " "
<< name << " "
<< marks;
}
};
If the following objects are created,
Student s1;
Student s2;
Student s3;
Memory is allocated separately for each object.
Working of Memory Allocation:
The memory allocation process takes place in the following steps:
1. The class is defined.
2. No memory is allocated for the class.
3. An object is created.
4. Memory is allocated for all data members of the object.
5. Each newly created object receives a separate memory block.
6. Member functions are shared by all objects.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 37
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
void display()
{
cout << "Roll Number : " << rollNo << endl;
cout << "Name : " << name << endl;
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 38
}
};
int main()
{
Student s1, s2;
s1.rollNo = 101;
s1.name = "Rahul";
s2.rollNo = 102;
s2.name = "Priya";
cout << "Object s1n";
s1.display();
cout << "nObject s2n";
s2.display();
return 0;
}
Output:
Object s1
Roll Number : 101
Name : Rahul
Object s2
Roll Number : 102
Name : Priya
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 39
Characteristics of Object Memory:
 Every object occupies a separate memory location.
 Each object stores its own copy of data members.
 Changing one object's data does not affect another object.
 Member functions are common to all objects.
 Memory is allocated only during object creation.
Advantages:
 Independent storage for each object.
 Efficient utilization of memory.
 Prevents accidental modification of another object's data.
 Supports multiple instances of the same class.
 Improves modularity and reliability.
Real-World Example:
Consider a Library Management System.
A Book class contains the following members:
 Book ID
 Book Name
 Author
 Price
Objects created from the class:
Book b1
Book b2
Book b3
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 40
Each object stores different information:
Object Book ID Book Name Price
b1 101 C++ Programming ₹550
b2 102 Data Structures ₹650
b3 103 Operating Systems ₹720
Although all books belong to the same class, each object has its own memory to store its data.
2.1.9 Advantages of Classes and Objects
Classes and objects are the foundation of Object-Oriented Programming. They provide a systematic
approach to software development by combining data and functions into a single unit. This improves
program organization, enhances security, and simplifies maintenance.
Advantages:
1. Code Reusability
A class can be reused to create multiple objects without rewriting the code.
2. Modularity
Large programs can be divided into smaller, manageable classes.
3. Data Encapsulation
Data members and member functions are grouped together, ensuring better organization.
4. Data Security
Private data members cannot be accessed directly from outside the class.
5. Easy Maintenance
Changes made to one class do not affect the entire program significantly.
6. Improved Readability
Classes make programs easier to understand and debug.
7. Real-World Modeling
Classes and objects closely represent real-world entities.
8. Flexibility
New objects can be created whenever required without modifying the class definition.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 41
2.1.10 Real-World Applications
Classes and objects are used in almost every modern software application. They help represent real-world
entities, making programs easier to design, develop, and maintain.
Applications of Classes and Objects
 Student Management System – Student, Course, Faculty, Attendance.
 Library Management System – Book, Member, Librarian.
 Hospital Management System – Doctor, Patient, Appointment.
 Banking System – Customer, Account, Transaction.
 Employee Management System – Employee, Department, Payroll.
 E-Commerce Applications – Product, Customer, Cart, Order.
 Hotel Management System – Room, Guest, Booking.
 Vehicle Management System – Car, Bike, Owner.
 Online Examination System – Student, Question, Result.
 School Management System – Teacher, Student, Classroom.
2.2 Access Specifiers
Access specifiers are one of the most important features of Object-Oriented Programming in C++. They
control the visibility and accessibility of data members and member functions of a class. Access specifiers
help implement data hiding and encapsulation, ensuring that sensitive data cannot be accessed directly
from outside the class.
C++ provides three access specifiers:
 Public
 Private
 Protected
These determine which members of a class can be accessed from different parts of a program.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 42
2.2.1 Introduction
In procedural programming, variables are often declared globally, allowing any function to access and
modify them. This can lead to accidental changes, making the program difficult to maintain and debug.
Object-Oriented Programming overcomes this limitation by using access specifiers, which restrict access to
class members. Depending on the required level of security, data members and member functions can be
declared as public, private, or protected.
Access specifiers improve software reliability by ensuring that only authorized parts of a program can access
specific data.
Need for Access Specifiers
The following are the primary reasons for using access specifiers:
 To protect sensitive data.
 To prevent unauthorized access.
 To implement data hiding.
 To improve software security.
 To control the accessibility of class members.
 To support encapsulation.
 To improve program maintainability.
 To simplify debugging.
Types of Access Specifiers
C++ provides three types of access specifiers:
1. Public
2. Private
3. Protected
Each provides a different level of accessibility.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 43
Characteristics of Access Specifiers:
 Control member accessibility.
 Improve data security.
 Support encapsulation.
 Restrict unauthorized access.
 Improve modular programming.
 Facilitate code maintenance.
 Improve software reliability.
2.2.2 Public Access Specifier
The public access specifier allows class members to be accessed from anywhere in the program. Public
members are accessible inside the class as well as outside the class through objects.
Public members generally represent the interface through which users interact with an object.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 44
Syntax:
class Student
{
public:
int rollNo;
void display()
{
}
};
Working:
When a data member or member function is declared as public, it becomes accessible through an object
using the dot (.) operator.
Example:
Student s1;
s1.rollNo = 101;
s1.display();
Example Program
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 45
void display()
{
cout << "Roll Number : " << rollNo << endl;
cout << "Name : " << name << endl;
}
};
int main()
{
Student s1;
s1.rollNo = 101;
s1.name = "Rahul";
s1.display();
return 0;
}
Output:
Roll Number : 101
Name : Rahul
Advantages:
 Easy access to members.
 Simple implementation.
 Useful for interface functions.
 Improves code readability.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 46
Limitations:
 Public data members reduce data security.
 Any function can modify the data.
 Violates encapsulation if overused.
Applications:
 Display functions
 Utility functions
 Interface methods
 Menu-driven programs
2.2.3 Private Access Specifier
The private access specifier is the default access level in a C++ class. Members declared as private cannot
be accessed directly from outside the class. They can only be accessed through public member functions.
Private members provide data security by hiding implementation details from users.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 47
Syntax:
class Student
{
private:
int rollNo;
public:
void setRollNo(int r)
{
rollNo = r;
}
void display()
{
cout << rollNo;
}
};
Working:
Private members remain hidden from external code.
Instead of accessing them directly,
s1.rollNo = 101; // Invalid
the object accesses them through public member functions.
s1.setRollNo(101);
s1.display();
Example Program:
#include<iostream>
using namespace std;
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 48
class Student
{
private:
int rollNo;
public:
void setRollNo(int r)
{
rollNo = r;
}
void display()
{
cout << "Roll Number : " << rollNo;
}
};
int main()
{
Student s1;
s1.setRollNo(101);
s1.display();
return 0;
}
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 49
Output:
Roll Number : 101
Advantages:
 Improves data security.
 Prevents unauthorized access.
 Supports encapsulation.
 Prevents accidental modification.
 Makes programs more reliable.
Limitations:
 Requires additional member functions.
 Slightly increases code size.
Applications:
 Banking software
 Hospital management systems
 Student databases
 Payroll systems
 Inventory management systems
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 50
2.2.4 Protected Access Specifier
The protected access specifier is similar to the private access specifier, but with one important difference.
Protected members cannot be accessed directly outside the class; however, they can be accessed by derived
classes during inheritance.
Protected members are primarily used in inheritance to allow derived classes to use selected members of the
base class while preventing direct access by external code.
Syntax:
class Student
{
protected:
int rollNo;
};
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 51
Characteristics:
 Accessible inside the class.
 Accessible in derived classes.
 Not accessible outside the class using objects.
 Mainly used in inheritance.
Example Program:
#include<iostream>
using namespace std;
class Student
{
protected:
int rollNo;
};
class Result : public Student
{
public:
void setData()
{
rollNo = 101;
}
void display()
{
cout << "Roll Number : " << rollNo;
}
};
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 52
int main()
{
Result r;
r.setData();
r.display();
return 0;
}
Output:
Roll Number : 101
Advantages:
 Supports inheritance.
 Protects data from external access.
 Allows controlled accessibility.
 Improves code reuse.
Applications:
 Base classes
 Framework development
 GUI libraries
 Software libraries
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 53
2.2.5 Comparison of Access Specifiers
The three access specifiers differ mainly in terms of accessibility.
Feature Public Private Protected
Accessible inside class Yes Yes Yes
Accessible outside class Yes No No
Accessible through objects Yes No No
Accessible in derived class Yes No Yes
Default access specifier No Yes No
Used for interface Yes No Sometimes
Used for data hiding Limited Yes Yes
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 54
Advantages of Using Access Specifiers:
 Improves program security.
 Supports encapsulation.
 Prevents accidental modification.
 Simplifies debugging.
 Enhances software reliability.
 Supports modular programming.
2.3 Member Functions
Member functions are functions declared inside a class that define the operations performed on the objects
of that class. They provide the behavior of the objects and can access the data members directly. Member
functions help manipulate the data stored in objects while maintaining data security through encapsulation.
Unlike ordinary functions, member functions belong to a class and are invoked using objects. They can be
defined either inside the class or outside the class using the scope resolution operator (::).
2.3.1 Introduction
A class contains two types of members:
 Data Members (Variables)
 Member Functions (Methods)
While data members store information, member functions perform operations on that information. Every
object created from a class can invoke the same member functions, although each object stores different data
values.
For example, a Student class may contain:
Data Members
 Roll Number
 Name
 Marks
Member Functions:
 acceptData()
 displayData()
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 55
 calculateGrade()
These functions operate on the data stored within the object.
Need for Member Functions:
Member functions are used to:
 Access data members.
 Modify object data.
 Display object information.
 Perform calculations.
 Implement business logic.
 Maintain data security.
 Support encapsulation.
 Improve code reusability.
Characteristics:
 Declared inside a class.
 Can access all data members.
 Invoked through objects.
 Can be defined inside or outside the class.
 Shared among all objects.
 Support encapsulation.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 56
2.3.2 Defining Member Functions Inside the Class
A member function may be defined directly inside the class definition. Such functions are treated as inline
functions by the compiler.
This approach is suitable for small functions because it improves readability and may reduce function call
overhead.
Syntax:
class ClassName
{
public:
void functionName()
{
}
};
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 57
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
void acceptData()
{
rollNo = 101;
name = "Rahul";
}
void displayData()
{
cout<<"Roll Number : "<<rollNo<<endl;
cout<<"Name : "<<name<<endl;
}
};
int main()
{
Student s1;
s1.acceptData();
s1.displayData();
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 58
return 0;
}
Output:
Roll Number : 101
Name : Rahul
Advantages:
 Easy to understand.
 Improves readability.
 Suitable for small functions.
 Compiler may optimize execution.
Limitations:
 Large functions reduce readability.
 Not suitable for lengthy implementations.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 59
2.3.3 Defining Member Functions Outside the Class
Large member functions are generally defined outside the class using the scope resolution operator (::).
This improves readability and keeps the class definition compact.
Syntax:
class Student
{
public:
void display();
};
void Student::display()
{
}
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 60
Scope Resolution Operator (::)
The scope resolution operator tells the compiler that the function belongs to a particular class.
Example:
Student::display()
means that display() belongs to the Student class.
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
void acceptData();
void displayData();
};
void Student::acceptData()
{
rollNo = 101;
name = "Rahul";
}
void Student::displayData()
{
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 61
cout<<"Roll Number : "<<rollNo<<endl;
cout<<"Name : "<<name<<endl;
}
int main()
{
Student s1;
s1.acceptData();
s1.displayData();
return 0;
}
Output:
Roll Number : 101
Name : Rahul
Advantages:
 Better program organization.
 Easy maintenance.
 Suitable for large applications.
 Improves readability.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 62
2.3.4 Inline Member Functions
An inline function is expanded at the place where it is called instead of performing a normal function call.
Member functions defined inside the class are generally treated as inline functions.
Syntax:
inline returnType functionName()
{
}
Example:
#include<iostream>
using namespace std;
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 63
class Square
{
public:
int number;
inline int square()
{
return number * number;
}
};
int main()
{
Square s;
s.number = 5;
cout<<"Square = "<<s.square();
return 0;
}
Output:
Square = 25
Advantages:
 Faster execution.
 Eliminates function call overhead.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 64
 Suitable for small functions.
 Limitations:
 Large inline functions increase program size.
 Compiler may ignore the inline request.
Applications:
 Getter functions.
 Setter functions.
 Mathematical calculations.
 Small utility functions.
2.3.5 Calling Member Functions
Member functions are invoked through objects using the dot (.) operator.
When a member function is called, it operates on the data members of the object through which it is
invoked.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 65
Syntax:
objectName.functionName();
Example:
Student s1;
s1.acceptData();
s1.displayData();
Example Program
#include<iostream>
using namespace std;
class Student
{
public:
void display()
{
cout<<"Welcome to Object-Oriented Programming";
}
};
int main()
{
Student s1;
s1.display();
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 66
return 0;
}
Output:
Welcome to Object-Oriented Programming
Rules for Calling Member Functions
 Object must be created first.
 Function must be accessible.
 Public member functions can be called directly.
 Private member functions can only be called from within the class.
Characteristics
 Called using objects.
 Uses the dot operator.
 Operates on object data.
 Can call other member functions.
 Can access private members.
Advantages:
 Easy to use.
 Supports modular programming.
 Improves code organization.
 Implements encapsulation.
 Promotes code reuse.
Real-World Example:
Consider a Bank Account class.
Member functions:
 openAccount()
 deposit()
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 67
 withdraw()
 displayBalance()
Each customer (object) invokes these functions independently.
Example:
Account a1;
a1.deposit();
a1.withdraw();
a1.displayBalance();
2.4 Array of Objects
An array of objects is a collection of objects of the same class stored in contiguous memory locations.
Similar to an array of primitive data types such as int, float, or char, an array of objects allows multiple
objects of a class to be managed using a single array name.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 68
Each element of the array is an independent object having its own copy of the data members while sharing
the member functions defined in the class.
Arrays of objects are widely used when a program needs to manage information about multiple entities such
as students, employees, books, products, customers, or bank accounts.
2.4.1 Introduction
In many real-world applications, a programmer needs to store information about multiple objects of the
same type. Creating individual objects for every entity becomes difficult when the number of objects is
large.
For example, if a college has 200 students, declaring individual objects such as
Student s1;
Student s2;
Student s3;
...
Student s200;
is not practical.
Instead, C++ provides arrays of objects, where all objects are stored using a single array.
Student s[200];
This simplifies program development and improves code readability.
Definition:
An array of objects is an array in which every element is an object of the same class.
Characteristics:
 All objects belong to the same class.
 Objects are stored in contiguous memory.
 Every object has independent data members.
 Member functions are shared.
 Objects are accessed using array indexing.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 69
 Index numbering starts from 0.
Applications:
Array of objects is used in
 Student Management System
 Employee Management System
 Hospital Management System
 Library Management System
 Banking Applications
 Inventory Management
 Hotel Management
 School ERP Systems
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 70
2.4.2 Declaration of an Array of Objects
An array of objects is declared in the same way as an array of primitive data types.
The only difference is that the data type is the class name.
Syntax:
ClassName objectArray[size];
Example:
Student student[50];
Employee emp[100];
Book books[25];
Here,
 student contains 50 Student objects.
 emp contains 100 Employee objects.
 books contains 25 Book objects.
Working:
Consider the declaration
Student s[3];
The compiler creates three independent objects.
s[0]
s[1]
s[2]
Each object contains
 rollNo
 name
 marks independently.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 71
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
};
int main()
{
Student s[3];
cout<<"Array of Objects Created Successfully";
return 0;
}
Output:
Array of Objects Created Successfully
Advantages:
 Easy declaration.
 Reduces programming effort.
 Supports bulk processing.
 Easy indexing.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 72
2.4.3 Initializing an Array of Objects
Once the array is declared, each object can be initialized separately.
Initialization is done using the array index and the dot (.) operator.
Syntax:
objectArray[index].dataMember=value;
Example:
Student s[3];
s[0].rollNo=101;
s[0].name="Rahul";
s[1].rollNo=102;
s[1].name="Priya";
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 73
s[2].rollNo=103;
s[2].name="Amit";
Every object stores different values.
Complete Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
};
int main()
{
Student s[3];
s[0].rollNo=101;
s[0].name="Rahul";
s[1].rollNo=102;
s[1].name="Priya";
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 74
s[2].rollNo=103;
s[2].name="Amit";
cout<<s[0].rollNo<<" "<<s[0].name<<endl;
cout<<s[1].rollNo<<" "<<s[1].name<<endl;
cout<<s[2].rollNo<<" "<<s[2].name<<endl;
return 0;
}
Output:
101 Rahul
102 Priya
103 Amit
Characteristics:
 Every object has separate values.
 Uses indexing.
 Uses dot operator.
 Supports sequential processing.
Advantages:
 Easy initialization.
 Simple data management.
 Efficient storage.
 Easy retrieval.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 75
2.4.4 Accessing Array Elements
Each object is accessed through its index number.
The syntax is
arrayName[index].member;
Example:
s[0].display();
s[1].display();
s[2].display();
Using Loop:
Arrays of objects are generally processed using loops.
for(int i=0;i<3;i++)
{
cin>>s[i].rollNo;
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 76
cin>>s[i].name;
}
Similarly,
for(int i=0;i<3;i++)
{
cout<<s[i].rollNo<<endl;
cout<<s[i].name<<endl;
}
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
};
int main()
{
Student s[3];
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 77
for(int i=0;i<3;i++)
{
cout<<"Enter Roll Number : ";
cin>>s[i].rollNo;
cout<<"Enter Name : ";
cin>>s[i].name;
}
cout<<"nStudent Detailsn";
for(int i=0;i<3;i++)
{
cout<<"nRoll Number : "<<s[i].rollNo<<endl;
cout<<"Name : "<<s[i].name<<endl;
}
return 0;
}
Output:
Enter Roll Number : 101
Enter Name : Rahul
Enter Roll Number : 102
Enter Name : Priya
Enter Roll Number : 103
Enter Name : Amit
Student Details
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 78
Roll Number : 101
Name : Rahul
Roll Number : 102
Name : Priya
Roll Number : 103
Name : Amit
Advantages:
 Easy traversal.
 Loop processing.
 Efficient for large datasets.
 Simplifies coding.
Real-World Example:
Suppose a university stores details of 500 students.
Instead of
Student s1;
Student s2;
...
Student s500;
it creates
Student students[500];
Now all student records can be processed using loops.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 79
2.5 Objects as Function Arguments
In Object-Oriented Programming, objects can be passed as arguments to functions in the same way as
variables of primitive data types. Passing objects to functions enables efficient data processing, code reuse,
and modular program design. Depending on the application requirements, objects can be passed by value or
by reference.
When an object is passed to a function, the function can perform operations using the data members of that
object. This feature is widely used in applications such as banking systems, employee management,
inventory management, and student information systems.
2.5.1 Introduction
Functions are an essential part of programming because they divide a large program into smaller,
manageable modules. In C++, functions can receive objects as parameters and can also return objects.
Passing objects to functions improves modularity and allows operations to be performed on complete objects
instead of individual variables.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 80
For example, in a Student Management System, a function may receive a Student object and display its
details or calculate its grade.
Need for Passing Objects to Functions:
Passing objects to functions is useful for:
 Processing complete objects.
 Improving code reusability.
 Simplifying program development.
 Reducing code duplication.
 Supporting modular programming.
 Improving readability.
 Allowing functions to manipulate object data.
 Passing multiple data members together.
Characteristics:
 Objects are passed like ordinary variables.
 Entire object is transferred.
 Member functions can access object data.
 Supports modular programming.
 Can be passed by value or reference.
 Objects may also be returned from functions.
Applications:
Objects as function arguments are commonly used in:
 Student Management Systems
 Employee Payroll Systems
 Banking Applications
 Hospital Management Systems
 Library Management Systems
 E-Commerce Applications
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 81
2.5.2 Passing Objects by Value
When an object is passed by value, a copy of the original object is created inside the called function. Any
modifications made to the copied object do not affect the original object.
This method is suitable when the function only needs to read or temporarily process object data.
Working:
Consider the following object:
Student s1;
The function call
display(s1);
creates a duplicate object inside the function.
Function Parameter (temp object)
The original object remains unchanged.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 82
Syntax:
functionName(ClassName object);
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
};
// Function receives object by value
void display(Student s)
{
cout<<"Roll Number : "<<s.rollNo<<endl;
cout<<"Name : "<<s.name<<endl;
}
int main()
{
Student s1;
s1.rollNo=101;
s1.name="Rahul";
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 83
display(s1);
return 0;
}
Output
Roll Number : 101
Name : Rahul
Advantages
 Original object remains safe.
 Suitable for read-only operations.
 Simple implementation.
 No accidental modification.
Limitations
 Creates an additional copy.
 More memory consumption.
 Slower for large objects.
2.5.3 Passing Objects by Reference
Passing an object by reference means that the function receives the actual object rather than a copy.
Therefore, any modifications made inside the function affect the original object.
Reference passing improves efficiency because no duplicate object is created.
Syntax:
functionName(ClassName &object);
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 84
Working:
Original Object
|
Reference Variable
|
Function operates directly
on the original object
No duplicate object is created.
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int marks;
};
// Passing object by reference
void updateMarks(Student &s)
{
s.marks = 95;
}
int main()
{
Student s1;
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 85
s1.marks=80;
updateMarks(s1);
cout<<"Updated Marks : "<<s1.marks;
return 0;
}
Output:
Updated Marks : 95
Advantages
 No duplicate object.
 Faster execution.
 Lower memory consumption.
 Changes reflected in original object.
 Suitable for large objects.
Limitations
 Original object can be modified.
 Requires careful programming.
Applications
 Updating records.
 Banking transactions.
 Inventory management.
 Employee salary updates.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 86
2.5.4 Returning Objects from Functions
A function in C++ can also return an object. This allows one function to create or modify an object and send
it back to the calling function.
Returning objects makes programs modular and simplifies object manipulation.
Syntax:
ClassName functionName()
{
ClassName obj;
return obj;
}
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 87
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
int rollNo;
string name;
};
// Function returning an object
Student getData()
{
Student s;
s.rollNo=101;
s.name="Rahul";
return s;
}
int main()
{
Student s1;
s1=getData();
cout<<"Roll Number : "<<s1.rollNo<<endl;
cout<<"Name : "<<s1.name<<endl;
return 0;
}
Output:
Roll Number : 101
Name : Rahul
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 88
Working:
1. Function creates an object.
2. Object is initialized.
3. Object is returned.
4. Calling function receives the object.
5. Returned object is assigned to another object.
Advantages
 Improves modularity.
 Supports object-oriented design.
 Simplifies coding.
 Easy object transfer.
Applications
 Returning student details.
 Returning bank account information.
 Returning employee records.
 Returning product details.
.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 89
2.5.5 Comparison: Passing by Value vs Passing by Reference
Feature Passing by Value Passing by Reference
Object Copy Created Not Created
Memory Usage More Less
Execution Speed Slower Faster
Original Object Unchanged Modified
Safety High Moderate
Suitable For Read-only operations Updating objects
Performance Lower Higher
Advantages of Using Objects as Function Arguments
 Improves modularity.
 Reduces code duplication.
 Simplifies object manipulation.
 Supports reusable code.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 90
 Enables efficient data processing.
 Improves readability.
 Suitable for large software projects.
2.6 Constructors and Destructors
Constructors and destructors are special member functions in C++ that are automatically invoked during the
lifetime of an object. A constructor initializes an object when it is created, whereas a destructor performs
cleanup activities before an object is destroyed. These special functions help automate object initialization
and resource management, making programs more reliable and efficient.
Constructors eliminate the need for separate initialization functions, while destructors ensure that resources
such as dynamically allocated memory, files, and network connections are properly released.
2.6.1 Introduction
When an object is created, its data members may contain garbage values if they are not initialized.
Initializing every object manually is time-consuming and error-prone.
To overcome this problem, C++ provides a special member function called the constructor, which is
executed automatically whenever an object is created.
Similarly, when an object goes out of scope or is destroyed, another special member function called the
destructor is executed automatically.
Thus, constructors and destructors manage the complete life cycle of an object.
Need for Constructors and Destructors:
Constructors and destructors are used to:
 Initialize objects automatically.
 Eliminate garbage values.
 Allocate system resources.
 Release allocated resources.
 Simplify object management.
 Improve program reliability.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 91
 Support object-oriented programming.
 Automate memory management.
Characteristics:
 Both are special member functions.
 Invoked automatically by the compiler.
 Constructor executes during object creation.
 Destructor executes during object destruction.
 Neither has a return type.
 Constructor can be overloaded.
 Destructor cannot be overloaded.
2.6.2 Constructor
A constructor is a special member function that is automatically called whenever an object is created. Its
primary purpose is to initialize the data members of the object.
The constructor has the same name as the class and does not have any return type, not even void.
Definition
A constructor is a special member function that automatically initializes an object when it is created.
Characteristics of Constructors:
 Same name as the class.
 No return type.
 Invoked automatically.
 Initializes object data.
 Can be overloaded.
 Usually declared in the public section.
 Executed only once per object.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 92
Syntax:
class ClassName
{
public:
ClassName()
{
}
};
Working:
When an object is created,
Student s1;
the constructor executes automatically.
Object Created
│
▼
Constructor Called
│
▼
Memory Initialized
│
▼
Object Ready to Use
Example Program
#include<iostream>
using namespace std;
class Student
{
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 93
public:
Student()
{
cout<<"Constructor Executed"<<endl;
}
};
int main()
{
Student s1;
return 0;
}
Output:
Constructor Executed
Advantages:
 Automatic initialization.
 Eliminates garbage values.
 Improves reliability.
 Reduces coding effort.
 Makes programs more organized.
Limitations:
 Cannot return values.
 Cannot be virtual.
 Cannot be inherited.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 94
Applications
 Object initialization.
 Database connection.
 File opening.
 Dynamic memory allocation.
 Network initialization.
2.6.3 Rules for Constructors
The following rules apply to constructors in C++.
1. Constructor name must be the same as the class name.
2. Constructors have no return type.
3. Constructors are called automatically.
4. Constructors cannot be inherited.
5. Constructors can be overloaded.
6. Constructors are generally declared in the public section.
7. A constructor executes only once for each object.
8. Constructors cannot be declared as static.
9. Constructors cannot be virtual.
10. Constructors may have default arguments.
Advantages
 Automatic execution.
 Supports object initialization.
 Improves code readability.
 Eliminates manual initialization.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 95
2.6.4 Destructor
A destructor is a special member function that is automatically executed when an object is destroyed. It
performs cleanup operations such as releasing memory, closing files, disconnecting databases, and freeing
system resources.
The destructor name is the same as the class name but is preceded by a tilde (~).
Definition:
A destructor is a special member function that is automatically called when an object is destroyed.
Syntax
class Student
{
public:
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 96
~Student()
{
}
};
Characteristics:
 Same name as class.
 Prefixed with ~.
 No return type.
 Automatically called.
 Executes once.
 Cannot be overloaded.
 Only one destructor per class.
Working:
Object Created
│
▼
Constructor Executes
│
▼
Program Execution
│
▼
Object Destroyed
│
▼
Destructor Executes
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 97
Example Program:
#include<iostream>
using namespace std;
class Student
{
public:
Student()
{
cout<<"Constructor Executed"<<endl;
}
~Student()
{
cout<<"Destructor Executed"<<endl;
}
};
int main()
{
Student s1;
return 0;
}
Output:
Constructor Executed
Destructor Executed
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 98
Advantages:
 Releases resources automatically.
 Prevents memory leaks.
 Closes files automatically.
 Improves memory management.
 Supports resource cleanup.
Limitations:
 Cannot be overloaded.
 Cannot accept parameters.
 Only one destructor allowed.
Applications:
 Closing files.
 Freeing dynamic memory.
 Closing database connections.
 Releasing sockets.
 Cleaning temporary data.
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 99
2.6.5 Difference between Constructor and Destructor
Feature Constructor Destructor
Purpose Initializes objects Releases resources
Symbol ClassName() ~ClassName()
Execution During object creation During object destruction
Parameters Allowed Not Allowed
Overloading Possible Not Possible
Number Multiple Only One
Automatic Call Yes Yes
Return Type None None
Sanjivani Rural Educational Society’s
SANJIVANI COLLEGE OF ENGINEERING
(An Autonomous Institution)
Kopargaon – 423 603, Maharashtra.
ACAD-F-15
Academic Year:
2026-2027
PCIT211: Object Oriented Programming Revision : 00
Term – I Department : Information Technology Date of Preparation :
01/07/2026
Course Owner: - Mr. A.S.Dalvi Department of Information Technology Class- S.Y.B. Tech. 100
Advantages of Constructors and Destructors
 Automatic object management.
 Simplifies coding.
 Prevents garbage values.
 Improves memory management.
 Reduces programming errors.
 Supports resource allocation and deallocation.
 Enhances software reliability.
2.7 Types of Constructors
A constructor is automatically invoked when an object is created. Depending on the number and type
of arguments, constructors are classified into different types. C++ allows multiple constructors in the
same class, enabling objects to be initialized in different ways. This concept is known as constructor
overloading.
The commonly used types of constructors are:
 Default Constructor
 Parameterized Constructor
 Copy Constructor
 Dynamic Constructor
 Constructor Overloading
Each type serves a specific purpose and improves the flexibility of object creation.
2.7.1 Introduction
Different applications require different methods of object initialization. Sometimes objects are initialized
with fixed values, sometimes with user-supplied values, and sometimes by copying existing objects.
To support these requirements, C++ provides different types of constructors.