What is the output of the following Python code snippet?
class A:
def __init__(self, x):
self.x = x
print(A(10).x)
def __init__(self, x):
self.x = x
print(A(10).x)
Correct answer
D. 10
D. 10
Instance attributes set in __init__ are accessed using dot notation.
Asked in: Python Interview OOP
https://docs.python.org/3/tutorial/classes.htmlNot sure why the answer is D? Ask here and get an explanation.