What are the differences between public, private, and
protected access?

Answer Posted / it

Public is used for global access so its scope is not only
within the class but also outside the class. For example
public variables will be visible to all classes and any
class or member function can utilize those variables and
member functions.

Private is used only in the class in which it is defined.
It cannot be accessible by its derived members. So private
variables will be visible only to the class to which they
belong and it will not give access to any other classes.
Public and protected members will become private in derived
class.

Protected is used within the class in which it is defined
and derived members of it can also access it. So protected
variables will be visible only to the class to which they
belong and it gave access to its derived classes also.

Is This Answer Correct ?    17 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain shallow copy?

616


Can we use this pointer inside static member function?

630


What is late binding c++?

544


What do you mean by translation unit?

606


Eplain extern keyword?

565






What is the type of this pointer in c++?

634


What is a responder chain?

578


What is an adaptor class in c++?

608


What is math h in c++?

608


What is extern c++?

523


Is recursion allowed in inline functions?

610


What are the 3 levels of programming languages?

539


Declare a class vehicle and make it an abstract data type.

539


Will this c++ program execute or not?

606


What is a tuple c++?

550