What Will Be The Output Of The Following Python Codep Pre #1145
What will be the output of the following Python code?</p> <pre><code class="language-python"> class Demo: def __init__(self): self.a = 1 self.__b = 1 def get(self): return self.__b obj = Demo() obj.a=45 print(obj.a) </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs109 Python. It can also be found in gs gs109 Python OOPs - Python Encapsulation - Quiz No.1.
What will be the output of the following Python code?
class Demo: def __init__(self): self.a = 1 self.__b = 1 def get(self): return self.__b obj = Demo() obj.a=45 print(obj.a)
The program runs properly and prints 45
The program has an error because the value of members of a class can’t be changed from outside the class
The program runs properly and prints 1
The program has an error because the value of members outside a class can only be changed as self.a=45