0% found this document useful (0 votes)
5 views2 pages

Module 7

The document outlines a programming module focused on object-oriented programming in Python, specifically covering inheritance types such as single, multiple, multilevel, and hybrid. It provides example code demonstrating these concepts through classes like Organism, Animal, Mammal, Flyer, and Bat, as well as method overriding in classes Vehicle, Car, Bike, and Truck. The document includes code snippets and expected outputs for each example.

Uploaded by

Girishan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Module 7

The document outlines a programming module focused on object-oriented programming in Python, specifically covering inheritance types such as single, multiple, multilevel, and hybrid. It provides example code demonstrating these concepts through classes like Organism, Animal, Mammal, Flyer, and Bat, as well as method overriding in classes Vehicle, Car, Bike, and Truck. The document includes code snippets and expected outputs for each example.

Uploaded by

Girishan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like