Python Programming - Encapsulation
Exercise : Encapsulation - General Questions
- Encapsulation - General Questions
1.
In Python, what is encapsulation?
Answer: Option
Explanation:
Encapsulation in Python involves bundling the data and methods of a class and controlling access to the internal details, exposing only the necessary functionalities.
2.
Which access specifier in Python is used to indicate that a variable or method should only be accessed within the same class?
Answer: Option
Explanation:
Private access specifier in Python is denoted by a single underscore (
_
), and it indicates that the variable or method should only be accessed within the same class.
3.
What is the purpose of the
@property
decorator?
Answer: Option
Explanation:
The
@property
decorator is used in Python to define a getter method for a class attribute, allowing controlled access.
4.
Which of the following statements about encapsulation in Python is true?
Answer: Option
Explanation:
Encapsulation in Python involves bundling data and methods into a single unit, promoting modularity and controlled access.
5.
What is the main advantage of encapsulation in object-oriented programming?
Answer: Option
Explanation:
The main advantage of encapsulation is that it enhances data security by hiding the implementation details of an object, preventing direct access and manipulation.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers