Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 95)
95.
What is the primary purpose of the following Python class?
class Car:
    def __init__(self, model, __speed):
        self.model = model
        self.__speed = __speed

    def get_speed(self):
        return self.__speed
To create a new instance of the class
To provide controlled access to the 'speed' variable
To define a public variable 'speed'
To allow unrestricted access to the 'speed' variable
Answer: Option
Explanation:
The get_speed() method provides controlled and read-only access to the private variable '__speed', demonstrating encapsulation.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.