Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 30)
30.
Consider the following Python code:
class Student:
    def __init__(self, name, age):
        self._name = name
        self._age = age

    def get_name(self):
        return self._name

    def set_age(self, new_age):
        if new_age >= 0:
            self._age = new_age
What concept of encapsulation is demonstrated in this code?
Public access specifier
Private access specifier
Protected access specifier
Global variable
Answer: Option
Explanation:
The single underscore prefix (_) in the variables _name and _age indicates that they are private variables, demonstrating encapsulation by hiding the implementation details.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.