DifferenceModerate2 marks
How are private members of a class different from public members?
Topic: private and public members
Previous-year question practice database
Answer
Exam answer
The difference is shown in the table.
Explanation
The difference is one of scope, so state the extent of access for each. Worth adding the reason: in encapsulation the data members are made private and public methods are provided to read or change them, so that all access passes through controlled code. That sentence turns a bare difference into an answer that shows understanding.
Comparison
| private members | public members |
|---|---|
| Accessible only within the class in which they are declared. | Accessible from anywhere in the program, including other classes. |
| Used for data members, so that they are protected from outside interference — the basis of encapsulation. | Used for methods that form the interface of the class. |
More from Encapsulation
Which of the following is NOT an access specifier?2026Post office is an example for __________ access specifier.2025The access specifier that gives least accessibility is __________.2024Assertion (A): Static method can access static and instance variables.
Reason (R): Static variables can be accessed only by static method.2024A mechanism where one class acquires the properties of another class:2023A method which is a part of a class rather than an instance of the class is termed as:2023