Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 79)
79.
What is the primary purpose of the following Python class?
class Movie:
    def __init__(self, title, __rating):
        self.title = title
        self.__rating = __rating

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

Post your comments here:

Your comments will be displayed after verification.