Question:

Define the following: (i) Public (ii) Protected (iii) Private

Show Hint

Access modifiers control data access in object-oriented programming and help implement encapsulation.
Updated On: Mar 14, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understand access specifiers.
Access specifiers are used in object-oriented programming to control the accessibility of variables and methods within a class.
Step 2: Define Public.
Public members can be accessed from anywhere in the program. They have no access restrictions.
Step 3: Define Protected.
Protected members can be accessed within the class and its subclasses. They are usually indicated with a single underscore prefix in Python.
Step 4: Define Private.
Private members can be accessed only within the class where they are defined.
They are generally represented using a double underscore prefix.
Step 5: Conclusion.
Thus public members are accessible everywhere, protected members within class hierarchy, and private members only within the class.
Was this answer helpful?
0
0