Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 50)
50.
Consider the following Python code:
class Employee:
    def __init__(self, name, salary):
        self._name = name
        self._salary = salary

    def get_salary(self):
        return self._salary
What is the purpose of the get_salary() method in this code?
To set the salary of an employee
To delete the salary of an employee
To retrieve the salary of an employee
To create a new instance of the class
Answer: Option
Explanation:
The get_salary() method is designed to retrieve the salary of an employee, 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.