Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 28)
28.
What will be the output of the following Python code?
class Parent:
    def __init__(self, x):
        self.x = x

class Child(Parent):
    def __init__(self, x, y):
        super().__init__(x)
        self.y = y

obj = Child(10, 20)
result = obj.x + obj.y
print(result)
30
20
This code will result in an error.
10
Answer: Option
Explanation:
The child class Child initializes both x and y, and the result is the sum of these attributes.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.