Advertisements
Advertisements
Question
Which of the following statements is the most appropriate for the private members?
Options
They are visible out of the class in which they are defined.
They can be used in the sub-classes.
They are only visible in the class in which they are declared.
None of the above.
MCQ
Solution
They are only visible in the class in which they are declared.
Explanation:
Private is a keyword in programming languages that serves as an access modifier. When you declare an object as private, it can only be accessible within the class. We can, however, use the getter and setter methods to access private data. This keyword can be applied to attributes, methods, and constructors.
shaalaa.com
Is there an error in this question or solution?