Python Programming - Encapsulation
Exercise : Encapsulation - General Questions
- Encapsulation - General Questions
11.
What is the purpose of the single underscore prefix in Python, as in
_variable
?
Answer: Option
Explanation:
The single underscore prefix in Python, as in
_variable
, is used to indicate a protected variable.
12.
In Python, what is a getter method used for in the context of encapsulation?
Answer: Option
Explanation:
In encapsulation, a getter method is used to retrieve the value of a private variable.
13.
Which access specifier in Python is used to indicate that a variable or method should be accessible from anywhere, both within and outside the class?
Answer: Option
Explanation:
Public access specifier in Python is used to indicate that a variable or method should be accessible from anywhere, both within and outside the class.
14.
What is the role of the
@property
decorator in encapsulation?
Answer: Option
Explanation:
The
@property
decorator is used in encapsulation to provide a getter method for a private variable, allowing controlled access.
15.
How does encapsulation contribute to the concept of information hiding in object-oriented programming?
Answer: Option
Explanation:
Encapsulation contributes to information hiding by hiding the implementation details of an object and exposing only the necessary functionalities, promoting abstraction.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers