-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolymorphipsm2.py
75 lines (55 loc) · 1.3 KB
/
polymorphipsm2.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#Q1
class Shape:
def __init__(self):
pass
def area(self):
return 0
class Rectangle(Shape):
def __init__(self,length,width):
self.length = length
self.width = width
pass
def area(self):
areares = self.length * self.width
return areares
obj1 = Rectangle(10,4)
print(obj1.area())
#Q2
class Person:
def __init__(self,name):
self.name = name
class Student(Person):
def __init__(self,name,grade):
super().__init__(name)
self.grade = grade
def display(self):
print("Student's Name:",self.name)
print("Stuent's Grade:",self.grade)
stu1 = Student("AK","A")
stu1.display()
#Q3
class Vehicle:
def __init__(self):
pass
def start(self):
print("Vehicle Started")
class Car(Vehicle):
def __init__(self):
pass
def start(self):
print("Car Started")
vh1 = Car()
vh1.start()
#Q4
class Employee:
def __init__(self,name,salary):
self.name = name
self.salary = salary
class Manager(Employee):
def __init__(self,name,salary,department):
super().__init__(name,salary)
self.department = department
def display(self):
print(self.name,self.salary,self.department)
emp1 = Manager("Mg1",100000,"IT")
emp1.display()