Skip to content

Latest commit

聽

History

History
20 lines (14 loc) 路 847 Bytes

File metadata and controls

20 lines (14 loc) 路 847 Bytes

馃悷 Method Overriding-Fish and Shark Class Inheritance in Python

馃 AIM:

To write a Python program that demonstrates class inheritance by creating a parent class Fish with a method type, and a child class Shark that overrides the type method.

馃搵 ALGORITHM:

  1. Define the Fish class with a method named type() that prints "fish".
  2. Define the Shark class as a subclass of Fish, and override the type() method to print "shark".
  3. Create an instance of the Fish class named obj_goldfish.
  4. Create an instance of the Shark class named obj_hammerhead.
  5. Use a for loop to iterate over both objects.
  6. Within the loop, call the type() method using the loop variable.
  7. Output will demonstrate method overriding: printing "fish" and "shark" accordingly.

馃捇 PROGRAM:

OUTPUT

RESULT