x

Choose Country Code

x

Direction

x

Ask a Question

  • Ask a Question
  • Scan a Question
  • Post MCQ
  • Note: File extension must be of jpg, jpeg, png, bmp format and file size must not exceed 5 MB
x

Ask a Question

x

x
x
x
Hire a Tutor

Answers and Solutions

What's Your Question?
Answer

 

Access Specifiers for the class member in c++

  • private - members are accessible to class only
  • public - members are accessible to class and outside from the class
  • protected - members are accessible to class and in inheritance level, but not outside the class
Answer
Private: accessed by only same class or friend function. Protected:Accessed by member of same class and derive class. public : can accessed by any class member.
Answer

Access Specifiers for the class member in c++

  • private - members are accessible to class only
  • public - members are accessible to class and outside from the class
  • protected - members are accessible to class and in inheritance level, but not outside the class
Answer

Access specifiers in C++ class define the access control rules. C++ has 3 new keywords introduced, namely,

public private protected

These access specifiers are used to set boundaries for availability of members of class be it data members or member functions

Access specifiers in the program, are followed by a colon. You can use either one, two or all 3 specifiers in the same class to set different boundaries for different class members. They change the boundary for all the declarations that follow them.

Answer

there are 3 access specifiers in the class ,mostly only used are 2 Public & Private ,and the 3rd one is Protected which is very less used in classes.

Private access specifier: if we put a private a.s. in a class for a data member values then that data can't be inheritable outside that class 

same as for Public and protected . .

Answer

We have 3 access specifiers in C++

1. Private: Private data members cannot be accessed by outside members, but it can be accessed only the member functions of that class.

2. Public: Public data members can be accessed by any one.

3. Protected:Consider if we have multi level inheritance. Eg. class C derived from class B, class B derived from class A. And class A is a base class. Suppose if we have protected data member which is declared under class A, then that data member is behaved public to class B and behave private to class C.

Answer

Ther are three types of Access Specifier in C++

Public , Private , Protected

1. Public: means all the class members declared under public will be available to everyone.

2. Private: means that no one can access the class members declared private outside that class. By default class variables and member functions are private.

3. Protected: It is the last access specifier, and it is similar to private, it makes class member inaccessible outside the class. But they can be accessed by any subclass of that class.

Answer

Private: accessed by only same class or friend function.

Protected:Accessed by member of same class and derive class.

public : can accessed by any class member.

 

Answer

public, private and protected

Answer

There are 3 access specifiers in C++. These are:

Public: A public member is accessible from anywhere outside the class.

Private:

A private member variable or function cannot be accessed, or even viewed from outside the class. Only the class and friend functions can access private members. By default, all the members of a class are private.

Protected: A protected member variable or function is very similar to a private member but it provided one additional benefit that they can be accessed in child classes which are called derived classes.

Answer

The access restrictions to the class members is specified by the visiblity labels(keywords) public, private and protected sections within the class. These keywords  are called 'Access Specifiers'. There are a lot to tell/explain about these.

Post Answer and Earn Credit Points

Get 5 credit points for each correct answer. The best one gets 25 in all.

Post Answer