Python Programming - Encapsulation - Discussion
Discussion Forum : Encapsulation - General Questions (Q.No. 57)
57.
Consider the following Python class:
class Student:
def __init__(self, name, age):
self._name = name
self._age = age
def display_student_info(self):
return f"Name: {self._name}, Age: {self._age}"
What encapsulation concept is demonstrated in this code?
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers