Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 61)
61.
Consider the following Python code:
class Person:
    def __init__(self, name, __age):
        self.name = name
        self.__age = __age

    def get_age(self):
        return self.__age
What is the purpose of the get_age() method?
To set the age of a person
To retrieve the age of a person
To delete the age of a person
To create a new instance of the class
Answer: Option
Explanation:
The get_age() method is designed to retrieve the private variable __age, demonstrating encapsulation by providing controlled access.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.