-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity2.py
More file actions
44 lines (35 loc) 路 899 Bytes
/
Copy pathactivity2.py
File metadata and controls
44 lines (35 loc) 路 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Define the base class Animal
class Animal:
def move(self):
pass # Placeholder for polymorphism
# Define the Dog subclass
class Dog(Animal):
def move(self):
print("Running on four legs!")
# Define the Bird subclass
class Bird(Animal):
def move(self):
print("Flying in the sky!")
# Define the Fish subclass
class Fish(Animal):
def move(self):
print("Swimming in the water!")
# Create objects of each subclass
my_dog = Dog()
my_bird = Bird()
my_fish = Fish()
# Call the move() method on each object
my_dog.move()
my_bird.move()
my_fish.move()
# Defining vehicle classes
class Car:
def move(self):
print("Driving on the road 馃殫")
class Plane:
def move(self):
print("Flying in the air 鉁堬笍")
# Creating objects and calling the move() method
vehicles = [Car(), Plane()]
for vehicle in vehicles:
vehicle.move()