Vidyalelo
Python · Q27

Concept of Object Oriented Programs in Python

Programming · Python · question 27

Q27

What will be the output of the following Python code? class Demo: def __init__(self): self.a = 1 self.__b = 1 def display(self): return self.__b obj = Demo() print(obj.a)

A.
The program has an error because there isn't any function to return self.a
B.
The program has an error because b is private and display(self) is returning a private member
C.
The program runs fine and 1 is printed
Answer
D.
The program has an error as you can't name a class member using __b

Answer: Option C

Solution

Answer: Option C
No explanation is given for this question Let's Discuss on Board