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?
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers