What are the differences between public, private, and
protected access?
Answer Posted / 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 |
Post New Answer View All Answers
How delete [] is different from delete?
What are the implicit member functions of class?
Do you know the problem with overriding functions?
Write a program to add three numbers in C++ utilizing classes.
what are Operators and explain with an example?
Of the numbers 12 23 9 28 which would be at the top of a properly implemented maxheap a) 28 b) 9 c) Any of them could be
Write about the role of c++ in the tradeoff of safety vs. Usability?
What are dynamic type checking?
Can we specify variable field width in a scanf() format string? If possible how?
What is a manipulator in c++?
Name the implicit member functions of a class.
How many standards of c++ are there?
write a program that withdrawals,deposits,balance check,shows mini statement. (using functions,pointers and arrays)
What is the use of seekg in c++?
What are the basics of local (auto) objects?