Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class, Objects, defining member functions, Arrays of Objects, Pointers and classes, Static Data Members, Static Member Functions, Passing Objects as Function Arguments, constructors, types of constructors, destructors, this pointer, Access Specifier , Fri

Rating
-
Sold
-
Pages
36
Uploaded on
27-08-2025
Written in
2025/2026

Class, Objects, defining member functions, Arrays of Objects, Pointers and classes, Static Data Members, Static Member Functions, Passing Objects as Function Arguments, constructors, types of constructors, destructors, this pointer, Access Specifier , Friend Functions, Inline functions.

Show more Read less
Institution
Course

Content preview

UNIT-3
Class, Objects, defining member functions, Arrays of Objects, Pointers and classes,
Static Data Members, Static Member Functions, Passing Objects as Function
Arguments, constructors, types of constructors, destructors, this pointer, Access
Specifier , Friend Functions, Inline functions.


Introduction of Class
An object oriented programming approach is a collection of objects and each
object consists of corresponding data members and member function.
Oops makes the program reusable and more maintainable. The important aspect in
oop is a class which has similar syntax that of structure.
class:
➢ It can also called as blue print or prototype that defines the variables and
functions common to all objects of certain kind.
➢ It is also known as user defined data type or ADT(abstract data type).
➢ A class is declared by the keyword class.
➢ Class is a product of Encapsulation and Data Abstraction of real world
object. Encapsulation means combine data and function into single unit and
data abstraction means declare members of the class as public, private and
protected.
➢ It is a collection of data and member functions that manipulate data.
Syntax:

, Object
In C++, an object is an instance of a class. Using object we can access data and
function using the dot operator (.).
Memory Allocation for Objects:
Memory for objects is allocated when they are declared but not when class is
defined.
All objects in a given class uses same member functions. The member functions
are created and placed in memory only once when they are defined in class
definition.
Memory is allocated to the object by run time or compiler when it is created.
Size of memory depends on sum of all the data members of the class.
There are few ways to create an object:
• Creating objects at the time of class declaration:
Class person
{
Public:
String name;
int age;
}p1,p2;
Here, p1,p2 are objects of person class.

• Using instance of the class (Static)
Syntax :
Classname variables;
Person obj;
Here, obj is an object of the class

• Using new operator(Dynamic)
Person *ptr=new Person();
This creates an object of type Person and returns a pointer to it.
The arrow operator (->) is used to access the member variable and functions of the
object.

,ptr->name=”RAM”;
ptr->age=30;

Access Specifier
Access specifier or access modifiers are the labels that specify type of access given
to members of a class. These are used for data hiding. These are also called as
visibility modes.
By using access specifiers, a class can control which members are accessible from
outside the class and which are not. They ensures the integrity of the class
implementation.

There are three types of access specifiers 1.private 2.public 3.protected

1.Private: If the data members are declared as private access then they cannot be
accessed outside the class, not even by objects of the class. It can only be accessed
by the functions declared within the class. It is declared by the key word “private” .

2.public: If the data members are declared public access then they can be accessed
anywhere in the program and from other functions outside the class. It is declared
by the key word “public”.

3.protected: The access level of protected declaration lies between public and
private. Its access properties are similar to private members. This access specifier
is used at the time of inheritance, they can be accessed by derived class.

Note:- 1.If the access specifier is not specified in the class the default access
specifier is private.
2.All member functions are to be declared as public if not they are not accessible
outside the class.
Example
#include<iostream>
#include<string>
using namespace std;
class student
{

private:
int roll;

, string name;

protected:
int age;

public:
void getdata()
{cout<<"Enter Roll number:";
cin>>roll;
cout<<"Enter Name:";
cin>>name;
}
void putdata()
{cout<<"Roll no:"<<roll<<endl;
cout<<"Name:"<<name<<endl;
cout<<"AGE :"<<age;
}

void protected_member()
{
cout<<"Enter age:";
cin>>age;
}
};
main()
{
student s;
s.getdata();
s.protected_member();
s.putdata();
}
OUTPUT :
Enter Roll number:22
Enter Name:RAM
Enter age:32
Roll no:22
Name:RAM
AGE :32

Written for

Course

Document information

Uploaded on
August 27, 2025
Number of pages
36
Written in
2025/2026
Type
Class notes
Professor(s)
Monika sharma
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
monika19sharmaa

Get to know the seller

Seller avatar
monika19sharmaa A private College
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
8 months
Number of followers
0
Documents
20
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions