Python Programming - Encapsulation - Discussion
Discussion Forum : Encapsulation - General Questions (Q.No. 88)
88.
How can encapsulation be enforced in Python to make a variable 'serial_number' accessible only within its own class?
class ElectronicDevice:
def __init__(self, serial_number, __brand):
self.serial_number = serial_number
self.__brand = __brand
Answer: Option
Explanation:
Adding a double underscore prefix before 'serial_number' 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