Python Programming - Encapsulation
Exercise : Encapsulation - General Questions
- Encapsulation - General Questions
31.
What is the purpose of the
@property
decorator in encapsulation?
Answer: Option
Explanation:
The
@property
decorator in encapsulation is used to provide a getter method for a private variable, allowing controlled access.
32.
In Python, what is a potential drawback of using encapsulation?
Answer: Option
Explanation:
A potential drawback of using encapsulation in Python is increased code complexity, especially if not managed properly.
33.
Which of the following is a common guideline when using encapsulation?
Answer: Option
Explanation:
A common guideline when using encapsulation is to provide getter and setter methods for private variables as needed to control access.
34.
How does encapsulation contribute to code maintenance?
Answer: Option
Explanation:
Encapsulation contributes to code maintenance in Python by combining data and methods into a single unit, making the code more modular and easier to manage.
35.
Consider the following Python code:
class Product:
def __init__(self, name, price):
self._name = name
self._price = price
@property
def get_price(self):
return self._price
What is the purpose of the @property
decorator in this code?
Answer: Option
Explanation:
The
@property
decorator in this code is used to provide a getter method for the private variable _price
.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers