in this post, you will learn about the access specifiers in c++ programming and learn how and why we use the access specifiers in c++ programming.
syntax:
<name-of-access-specifiers>:
Note: we can only use access specifiers in a class.
Note: always use [:] colon sign at the end of access specifiers.
Example:
public:
private:
protected:
Example:
class student
{
private:
int a;
char c;
};
you will fully understand the protected data when we learn about inheritance.
Example:
class student
{
protected:
int a;
char;
};
Example:
class student
{
public:
int a;
char c;
};
Note: always use the [;] semicolon at the end of the class.
"Please share this knowledge as much possible as you can and also comment me your queries and questions related to this topic. I will really grateful to help you."
![]() |
learn c++ programming |
Access specifiers:
To use different types of access control we used access specifiers. specifiers set the visibility of class members.Types of access specifiers in c++:
There are three types of access specifiers in c++ for a class.- Private
- Protected
- Public
syntax:
<name-of-access-specifiers>:
Note: we can only use access specifiers in a class.
Note: always use [:] colon sign at the end of access specifiers.
Example:
public:
private:
protected:
private:
all the data in private specifiers access inside the class.Example:
class student
{
private:
int a;
char c;
};
protected:
we can only use protected data from base class to driven class.you will fully understand the protected data when we learn about inheritance.
Example:
class student
{
protected:
int a;
char;
};
public:
we can access all the public data from outside or inside the class.Example:
class student
{
public:
int a;
char c;
};
Note: always use the [;] semicolon at the end of the class.
"Please share this knowledge as much possible as you can and also comment me your queries and questions related to this topic. I will really grateful to help you."
0 comments: