Python Programming - Encapsulation - Discussion
Discussion Forum : Encapsulation - General Questions (Q.No. 70)
70.
What is the purpose of the following Python code?
class Employee:
def __init__(self, name, __salary):
self.name = name
self.__salary = __salary
@property
def salary(self):
return self.__salary
Answer: Option
Explanation:
The @property decorator creates a read-only property 'salary', providing controlled access to the private variable '__salary'.
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