Analyze the following code:
 class

Loading

Choose the correct option.

Analyze the following code:
 class A:
     def __init__(self):
         self.x = 1
         self.__y = 1
 
     def getY(self):
         return self.__y
 a = A()
 a.x = 45
 print(a.x)

A. The program has an error because x is private and cannot be access outside of the class.
B. The program has an error because y is private and cannot be access outside of the class.
C. The program has an error because you cannot name a variable using __y.
D. The program runs fine and prints 1.

Leave a Comment