Python Programming - Objects - Discussion
Discussion Forum : Objects - General Questions (Q.No. 21)
21.
Consider the following Python code:
class Animal:
def __init__(self, species, legs):
self.species = species
self.legs = legs
def sound(self):
return "Unknown sound"
If you create an instance of the `Animal` class called dog
with species "Dog" and legs 4, what will be the result of calling dog.sound()
?
Answer: Option
Explanation:
The
sound
method returns "Unknown sound" by default. It can be overridden in derived classes to provide specific sound implementations.
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