How Are Private Members of a Class Different from Public Members ?
Advertisements
Question
How are private members of a class different from public members?
One Line Answer
Short Answer
Advertisements
Solution 1
The scope of the private members is within the class whereas the scope of the public members is global.
shaalaa.com
Solution 2
- Private:
- A private access specifier restricts access to a variable or method within a class.
- Private elements are not shared with other classes during inheritance.
- Public:
- A public specifier indicates that a variable or method is directly accessible from all classes.
- During inheritance, one class shares public elements with another.
shaalaa.com
Is there an error in this question or solution?
