Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 71)
71.
What is the primary purpose of the following Python class?
class Student:
    def __init__(self, name, __grade):
        self.name = name
        self.__grade = __grade

    def get_grade(self):
        return self.__grade
To create a new instance of the class
The get_grade() method provides access to the private variable 'grade'
To define a public variable 'grade'
To allow unrestricted access to the 'grade' variable
Answer: Option
Explanation:
The get_grade() method provides access to the private variable '__grade', demonstrating encapsulation.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.