Python Programming - Encapsulation - Discussion

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

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

Post your comments here:

Your comments will be displayed after verification.