Python Programming - Encapsulation - Discussion

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

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

Post your comments here:

Your comments will be displayed after verification.