Python Programming - Classes - Discussion
Discussion Forum : Classes - General Questions (Q.No. 35)
35.
Consider the following Python code:
class Animal:
def __init__(self, species):
self.species = species
class Fish(Animal):
def swim(self):
print(f"{self.species} is swimming")
# Create an instance of the Fish class
my_fish = Fish("Goldfish")
# Call the swim method
my_fish.swim()
What will be the output of the code?
Answer: Option
Explanation:
The code creates an instance of the `Fish` class and calls the `swim` method, which prints the message "{species} is swimming."
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