Python Programming - Encapsulation - Discussion
Discussion Forum : Encapsulation - General Questions (Q.No. 92)
92.
How can encapsulation be enforced in Python to make a variable 'employee_id' accessible only within its own class?
class Employee:
def __init__(self, employee_id, __salary):
self.employee_id = employee_id
self.__salary = __salary
Answer: Option
Explanation:
Adding a double underscore prefix before 'employee_id' makes it a private variable, enforcing encapsulation within the class.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers