Python Programming - Inheritance - Discussion
Discussion Forum : Inheritance - General Questions (Q.No. 67)
67.
Consider the following code:
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def speak(self):
print("Dog barks")
def main():
my_pet = Dog()
my_pet.speak()
What will be the output of the main() function?
Answer: Option
Explanation:
The
speak() method is overridden in the Dog class, so calling speak() on a Dog instance will print "Dog barks".
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