Python Programming - Inheritance - Discussion

Discussion Forum : Inheritance - General Questions (Q.No. 69)
69.
Consider the following code:
class A:
    def method(self):
        print("Method in class A")

class B(A):
    def method(self):
        print("Method in class B")

class C(B):
    pass

obj = C()
obj.method()
What will be the output of the obj.method() call?
Method in class A
Method in class B
The code will result in an error
Method in class C
Answer: Option
Explanation:
The method() is overridden in class B, and since class C inherits from class B, calling obj.method() will print "Method in class B".
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.