Python Programming - Encapsulation - Discussion
Discussion Forum : Encapsulation - General Questions (Q.No. 73)
73.
Consider the following Python code:
class Product:
def __init__(self, name, __price):
self.name = name
self.__price = __price
def set_price(self, new_price):
if new_price > 0:
self.__price = new_price
What is the purpose of the set_price() method?
Answer: Option
Explanation:
The set_price() method allows setting a new price for the product with validation, demonstrating encapsulation.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers