SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
Access Specifiers
Muhammad Hammad Waseem
Access Specifiers
• The commands that are used to specify the access level of class
members.
• These are used to enforce restrictions to members of a class.
• There are three access specifiers
• ‘public’ is used to tell that member can be accessed whenever you have
access to the object
• ‘private’ is used to tell that member can only be accessed from a member
function
• ‘protected’ to be discussed when we cover inheritance
Private Access Specifier
• The private access specifier is used to restrict the use of class member
within the class.
• Any member of the class declared with private access specifier can only be
accessed within the class.
• It cannot be accessed from outside the class.
• It is also the default access specifier.
• The data members are normally declared with private access specifier.
• It is because the data of an object is more sensitive.
• The private access specifier is used to protect the data member from direct
access from outside the class.
• These data members can only be used by the functions declared within the
class.
Public Access Specifier
• The public access specifier is used to allow the user to access a class
member within the class as well as outside the class.
• Any member of the class declared with public access specifier can be
accessed from anywhere in the program.
• The members functions are normally declared with public access
specifier.
• It is because the users access functions of an object from outside the class.
• The class cannot be used directly if both data members and member
functions are declared as private.
Example
class Student{
private:
char * name;
int rollNo;
public:
void setName(char *);
void setRollNo(int);
...
};
Cannot be accessed outside class
Can be
accessed
outside class
Example
class Student{
...
int rollNo;
public:
void setRollNo(int aNo);
};
int main(){
Student aStudent;
aStudent.SetRollNo(1);
}
Default Access Specifiers
• When no access specifier is mentioned then by default the member is
considered private member
class Student
{
char * name;
int RollNo;
};
class Student
{
private:
char * name;
int RollNo;
};
Example
class Student
{
char * name;
int RollNo;
void SetName(char *);
};
Student aStudent;
aStudent.SetName(Ali);
Error
Example
class Student
{
char * name;
int RollNo;
public:
void setName(char *);
};
Student aStudent;
aStudent.SetName(“Ali”);

More Related Content

What's hot (20)

PPT
Data members and member functions
Harsh Patel
 
PDF
Class and Objects in Java
Spotle.ai
 
PPTX
Access specifier
zindadili
 
PPTX
Access specifiers(modifiers) in java
HrithikShinde
 
PPTX
classes and objects in C++
HalaiHansaika
 
PDF
Access specifiers (Public Private Protected) C++
vivekkumar2938
 
PPTX
Object-oriented programming
Neelesh Shukla
 
PPTX
Classes and objects
rajveer_Pannu
 
PPTX
Constructor and Types of Constructors
Dhrumil Panchal
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPTX
Member Function in C++
NikitaKaur10
 
PPT
Class and object in C++
rprajat007
 
PPTX
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
PPTX
Inheritance in OOPS
Ronak Chhajed
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PPT
Function overloading(c++)
Ritika Sharma
 
PPTX
Chapter 07 inheritance
Praveen M Jigajinni
 
PPTX
Methods in java
chauhankapil
 
PPTX
Data members and member functions
Marlom46
 
Data members and member functions
Harsh Patel
 
Class and Objects in Java
Spotle.ai
 
Access specifier
zindadili
 
Access specifiers(modifiers) in java
HrithikShinde
 
classes and objects in C++
HalaiHansaika
 
Access specifiers (Public Private Protected) C++
vivekkumar2938
 
Object-oriented programming
Neelesh Shukla
 
Classes and objects
rajveer_Pannu
 
Constructor and Types of Constructors
Dhrumil Panchal
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Member Function in C++
NikitaKaur10
 
Class and object in C++
rprajat007
 
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Inheritance in OOPS
Ronak Chhajed
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Function overloading(c++)
Ritika Sharma
 
Chapter 07 inheritance
Praveen M Jigajinni
 
Methods in java
chauhankapil
 
Data members and member functions
Marlom46
 

Viewers also liked (20)

PPTX
Dynamic Polymorphism in C++
Dharmisha Sharma
 
PDF
Java Programming - 05 access control in java
Danairat Thanabodithammachari
 
PPSX
String and string manipulation x
Shahjahan Samoon
 
PPTX
[OOP - Lec 06] Classes and Objects
Muhammad Hammad Waseem
 
PDF
Oops (inheritance&interface)
Muthukumaran Subramanian
 
PPTX
[OOP - Lec 04,05] Basic Building Blocks of OOP
Muhammad Hammad Waseem
 
PPT
Lecture09
elearning_portal
 
PPTX
[OOP - Lec 09,10,11] Class Members & their Accessing
Muhammad Hammad Waseem
 
PPTX
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
Muhammad Hammad Waseem
 
PPTX
[OOP - Lec 03] Programming Paradigms
Muhammad Hammad Waseem
 
PPTX
Polymorphism in c++(ppt)
Sanjit Shaw
 
PPTX
[OOP - Lec 01] Introduction to OOP
Muhammad Hammad Waseem
 
PDF
Java packages and access specifiers
ashishspace
 
PPTX
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
Muhammad Hammad Waseem
 
PPTX
[OOP - Lec 02] Why do we need OOP
Muhammad Hammad Waseem
 
PPTX
[OOP - Lec 18] Static Data Member
Muhammad Hammad Waseem
 
PPTX
[OOP - Lec 20,21] Inheritance
Muhammad Hammad Waseem
 
PPTX
Inheritance in C++
Laxman Puri
 
PPT
Object Oriented Programming with Java
backdoor
 
PPTX
oops concept in java | object oriented programming in java
CPD INDIA
 
Dynamic Polymorphism in C++
Dharmisha Sharma
 
Java Programming - 05 access control in java
Danairat Thanabodithammachari
 
String and string manipulation x
Shahjahan Samoon
 
[OOP - Lec 06] Classes and Objects
Muhammad Hammad Waseem
 
Oops (inheritance&interface)
Muthukumaran Subramanian
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
Muhammad Hammad Waseem
 
Lecture09
elearning_portal
 
[OOP - Lec 09,10,11] Class Members & their Accessing
Muhammad Hammad Waseem
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
Muhammad Hammad Waseem
 
[OOP - Lec 03] Programming Paradigms
Muhammad Hammad Waseem
 
Polymorphism in c++(ppt)
Sanjit Shaw
 
[OOP - Lec 01] Introduction to OOP
Muhammad Hammad Waseem
 
Java packages and access specifiers
ashishspace
 
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
Muhammad Hammad Waseem
 
[OOP - Lec 02] Why do we need OOP
Muhammad Hammad Waseem
 
[OOP - Lec 18] Static Data Member
Muhammad Hammad Waseem
 
[OOP - Lec 20,21] Inheritance
Muhammad Hammad Waseem
 
Inheritance in C++
Laxman Puri
 
Object Oriented Programming with Java
backdoor
 
oops concept in java | object oriented programming in java
CPD INDIA
 
Ad

Similar to [OOP - Lec 07] Access Specifiers (20)

PPTX
C# Access modifiers
Prem Kumar Badri
 
PPTX
Friend function
Heet Patel
 
PPTX
Nested classes in java
ChiradipBhattacharya
 
PPTX
27csharp
Sireesh K
 
PPTX
27c
Sireesh K
 
PPTX
Access Modifiers of oop classes concept.pptx
umarshafi527
 
PDF
Chapter 03 enscapsulation
Nurhanna Aziz
 
PPTX
Classes and objects
Anil Kumar
 
PPT
Classes and objects
Lovely Professional University
 
PPT
Access Protection
myrajendra
 
PDF
Classes in Java great learning.pdf
SHASHIKANT346021
 
PPTX
class and object in c++.pptx
Adarsh College, Hingoli
 
PDF
‏‏oop lecture 2 taiz univercity object programming.pdf
nabeehmohammedtaher
 
PPTX
Java Inner Class
DeeptiJava
 
PPTX
Module 4_Ch3 - Abstraction and Encapsulation.pptx
jhesorleylaid2
 
PPTX
Object oriented programming introduction .pptx
azkamurat
 
PPT
A1771937735_21789_14_2018__16_ Nested Classes.ppt
RithwikRanjan
 
PPTX
object oriented programming unit two ppt
isiagnel2
 
PDF
Access modifiers in java
Muthukumaran Subramanian
 
PPTX
ACCESS SPECIFIERS AND ACCESS MODIFIERS IN C#.pptx
crishabh420
 
C# Access modifiers
Prem Kumar Badri
 
Friend function
Heet Patel
 
Nested classes in java
ChiradipBhattacharya
 
27csharp
Sireesh K
 
Access Modifiers of oop classes concept.pptx
umarshafi527
 
Chapter 03 enscapsulation
Nurhanna Aziz
 
Classes and objects
Anil Kumar
 
Classes and objects
Lovely Professional University
 
Access Protection
myrajendra
 
Classes in Java great learning.pdf
SHASHIKANT346021
 
class and object in c++.pptx
Adarsh College, Hingoli
 
‏‏oop lecture 2 taiz univercity object programming.pdf
nabeehmohammedtaher
 
Java Inner Class
DeeptiJava
 
Module 4_Ch3 - Abstraction and Encapsulation.pptx
jhesorleylaid2
 
Object oriented programming introduction .pptx
azkamurat
 
A1771937735_21789_14_2018__16_ Nested Classes.ppt
RithwikRanjan
 
object oriented programming unit two ppt
isiagnel2
 
Access modifiers in java
Muthukumaran Subramanian
 
ACCESS SPECIFIERS AND ACCESS MODIFIERS IN C#.pptx
crishabh420
 
Ad

More from Muhammad Hammad Waseem (18)

PDF
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 15] Arrays & its Types
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 14] Recursion
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 13] Introduction to Pointers
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 12] Functions in C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 11] Loops in C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 09] Conditional Operator in C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 08] Decision Control Structures (If Statement)
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 07] Comments in C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 05] Datatypes
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 04] Variables and Constants in C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 03] Introduction to C/C++
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
Muhammad Hammad Waseem
 
PDF
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
Muhammad Hammad Waseem
 
PPTX
Data Structures - Lecture 10 [Graphs]
Muhammad Hammad Waseem
 
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 15] Arrays & its Types
Muhammad Hammad Waseem
 
[ITP - Lecture 14] Recursion
Muhammad Hammad Waseem
 
[ITP - Lecture 13] Introduction to Pointers
Muhammad Hammad Waseem
 
[ITP - Lecture 12] Functions in C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 11] Loops in C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 09] Conditional Operator in C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
Muhammad Hammad Waseem
 
[ITP - Lecture 07] Comments in C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
Muhammad Hammad Waseem
 
[ITP - Lecture 05] Datatypes
Muhammad Hammad Waseem
 
[ITP - Lecture 04] Variables and Constants in C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 03] Introduction to C/C++
Muhammad Hammad Waseem
 
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
Muhammad Hammad Waseem
 
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
Muhammad Hammad Waseem
 
Data Structures - Lecture 10 [Graphs]
Muhammad Hammad Waseem
 

Recently uploaded (20)

PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Difference between write and update in odoo 18
Celine George
 
Horarios de distribución de agua en julio
pegazohn1978
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Introduction to Indian Writing in English
Trushali Dodiya
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Controller Request and Response in Odoo18
Celine George
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
infertility, types,causes, impact, and management
Ritu480198
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 

[OOP - Lec 07] Access Specifiers

  • 2. Access Specifiers • The commands that are used to specify the access level of class members. • These are used to enforce restrictions to members of a class. • There are three access specifiers • ‘public’ is used to tell that member can be accessed whenever you have access to the object • ‘private’ is used to tell that member can only be accessed from a member function • ‘protected’ to be discussed when we cover inheritance
  • 3. Private Access Specifier • The private access specifier is used to restrict the use of class member within the class. • Any member of the class declared with private access specifier can only be accessed within the class. • It cannot be accessed from outside the class. • It is also the default access specifier. • The data members are normally declared with private access specifier. • It is because the data of an object is more sensitive. • The private access specifier is used to protect the data member from direct access from outside the class. • These data members can only be used by the functions declared within the class.
  • 4. Public Access Specifier • The public access specifier is used to allow the user to access a class member within the class as well as outside the class. • Any member of the class declared with public access specifier can be accessed from anywhere in the program. • The members functions are normally declared with public access specifier. • It is because the users access functions of an object from outside the class. • The class cannot be used directly if both data members and member functions are declared as private.
  • 5. Example class Student{ private: char * name; int rollNo; public: void setName(char *); void setRollNo(int); ... }; Cannot be accessed outside class Can be accessed outside class
  • 6. Example class Student{ ... int rollNo; public: void setRollNo(int aNo); }; int main(){ Student aStudent; aStudent.SetRollNo(1); }
  • 7. Default Access Specifiers • When no access specifier is mentioned then by default the member is considered private member class Student { char * name; int RollNo; }; class Student { private: char * name; int RollNo; };
  • 8. Example class Student { char * name; int RollNo; void SetName(char *); }; Student aStudent; aStudent.SetName(Ali); Error
  • 9. Example class Student { char * name; int RollNo; public: void setName(char *); }; Student aStudent; aStudent.SetName(“Ali”);