CE0525 - Programming for Scientific Computing (Python)
MODULE : 7 - Object- Orientation Programs
7.1 Implement following inheritance: (1)Single (2) Multiple (3) Multilevel (4) Hybrid
Code: class Organism:
def live(self):
print("The organism is living")
class Animal(Organism):
def move(self):
print("The animal is moving")
class Mammal(Animal):
def milk(self):
print("The mammal drinks milk")
class Flyer:
def fly(self):
print("This creature can fly")
class Bat(Mammal, Flyer):
def sound(self):
print("Bat emits high frequency sounds")
b = Bat()
b.live()
b.move()
b.milk()
b.fly()
b.sound()
Output:
7.2 Demonstrate Overriding and methods to overcome.
Code: class Vehicle:
def start(self):
print("Vehicle is starting")
class Car(Vehicle):
def start(self):
print("Car is starting")
class Bike(Vehicle):
def start(self):
IU2341230191 44
CE0525 - Programming for Scientific Computing (Python)
super().start()
print("Bike is starting")
class Truck(Vehicle):
def start(self):
Vehicle.start(self)
print("Truck is starting")
v = Vehicle()
c = Car()
b = Bike()
t = Truck()
v.start()
c.start()
b.start()
t.start()
Output:
IU2341230191 45