Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 55)
55.
Consider the following Python code:
class Car:
    def __init__(self, model, speed):
        self._model = model
        self._speed = speed

    def display_info(self):
        return f"Model: {self._model}, Speed: {self._speed} km/h"
What encapsulation concept 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 _model and _speed 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.