Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 25)
25.
Consider the following Python code:
class Car:
    def __init__(self, model, year):
        self.__model = model
        self.__year = year

    def display_info(self):
        return f"Model: {self.__model}, Year: {self.__year}"
What concept of encapsulation is demonstrated in this code?
Public access specifier
Private access specifier
Protected access specifier
Global variable
Answer: Option
Explanation:
The double underscore prefix (__) in the variables __model and __year 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.