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

Answers were Sorted based on User's Feedback



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

Answer / swetcha

We use these keywords to specify access levels for member
variables, or for member functions (methods).

.Public variables, are variables that are visible to all
classes.

.Private variables, are variables that are visible only to
the class to which they belong.

.Protected variables, are variables that are visible only
to the class to which they belong, and any subclasses.


Deciding when to use private, protected, or public
variables is sometimes tricky. You need to think whether or
not an external object (or program), actually needs direct
access to the information. If you do want other objects to
access internal data, but wish to control it, you would
make it either private or protected, but provide functions
which can manipulate the data in a controlled way.

Is This Answer Correct ?    172 Yes 22 No

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

Answer / manjusinga

public is used for global access that is its scope is not
only within the class but also outside the class.

private is used only in the class class in which it is
defined.It cannot be accessible by its derived members.

protected is used within the class in which it is defined
and derived members of it can also access it.

Is This Answer Correct ?    133 Yes 10 No

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

Answer / golledla prathap reddy

public data can access anybody in the program.
private data can access olny members of that class.
protected also same like private but the difference is it
can access by derive class also.
we can see the use of protected data in inheritance.

Is This Answer Correct ?    64 Yes 12 No

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

Answer / krishnachaitanya narne adeesh

Public data is used to access from any where in the program
means any class or any member function can utilize those
variables and member functions.

Where as Private data will not give access to any other
classes and also for derived classes it use those variables
only on particular class only.

Here Protected is similar to Private but difference is just
it gave access to its derived classes also. This is also
opposite to Public.

Is This Answer Correct ?    46 Yes 9 No

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

Answer / bebo

prvate:is accessed by members of that class only.

public:is accessed by members of any class

protected: variables that are visible only
to the class to which they belong, and any subclasses.

Is This Answer Correct ?    22 Yes 4 No

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

Answer / alka choubey

public:class members are access from the outside the class.
private:class members are access only within the class.
protected:class members can access inside the same package.

Is This Answer Correct ?    29 Yes 13 No

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

Answer / prashant kalmodiya

PUBLIC: Specifies that those all members are accessible
from any function.

PRIVATE: Specifies that those members are accessible only
from member functions and friends functions of the class.

PROTECTED: Specifies access to class members in the member-
list up to the next access specifier (public or private)

Is This Answer Correct ?    18 Yes 8 No

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

Answer / 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

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

Answer / prashanth c patel

public-->inherite the protected members as preotected in
drived class and pubic members wiull be public in derived
class

protected--->pubic and protecated members of the base class
will become protected in derived class

Private-->pubilc and proteacted members will become private
in derived class

Is This Answer Correct ?    21 Yes 12 No

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

Answer / abhay

public-->inherite the protected members as preotected in
drived class and pubic members wiull be public in derived
class

protected--->pubic and protecated members of the base class
will become protected in derived class

Private-->pubilc and proteacted members will become private
in derived class

Is This Answer Correct ?    14 Yes 7 No

Post New Answer

More C++ General Interview Questions

What are the implicit member functions of class?

0 Answers  


How many namespaces are there in c++?

0 Answers  


What are punctuators in c++?

0 Answers  


What operators can you overload in c++?

0 Answers  


Explain the scope resolution operator?

2 Answers  






If all is successful, what should main return a) 0 b) 1 c) void

0 Answers  


What is while loops?

0 Answers  


What is an adaptor class or wrapper class in c++?

0 Answers  


What does extern mean in a function declaration in c++?

0 Answers  


Is it possible for the objects to read and write themselves?

0 Answers  


You have two pairs: new() and delete() and another pair : alloc() and free(). Explain differences between eg. New() and malloc()

0 Answers  


Can char be a number c++?

0 Answers  


Categories