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
Why we use #include iostream in c++?
What relational operators if statements in c++?
Arrange Doubly linked list in the ascending order of its integral value and replace integer 5 with 7?
In c++, what is the difference between method overloading and method overriding?
What is while loops?
How come you find out if a linked-list is a cycle or not?
Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)
Why is c++ difficult?
What is dynamic and static typing?
Can notepad ++ run c++?
What is a sequence in c++?
What are multiple inheritances (virtual inheritance)?
What is data type in c++?
What are default parameters? How are they evaluated in c++ function?
How to declare a function pointer?