-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass_inherit.py
50 lines (37 loc) · 897 Bytes
/
Class_inherit.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
# class inherit
class Car():
def exclaim(Self):
print("I'm a Car!")
#class Yugo(Car):
# pass
#print(issubclass(Yugo,Car))
#give_me_a_car = Car()
#give_me_a_yugo = Yugo()
#give_me_a_car.exclaim()
#give_me_a_yugo.exclaim()
# Method override
class Yugo(Car):
def exclaim(self):
print("I'm a Yugo! Much like a car, but more Yugo-ish.")
def need_a_push(self):
print("A little help here?")
give_me_a_car = Car()
give_me_a_yugo = Yugo()
give_me_a_car.exclaim()
give_me_a_yugo.exclaim()
class Person():
def __init__(self, name):
self.name = name
class MDPerson(Person):
def __init__(self, name):
self.name = "Doctor" + name
class JDPerson(Person):
def __init__(self, name):
self.name = name + ", Esquire"
person = Person('Fudd')
doctor = MDPerson('Fudd')
lawyer = JDPerson('Fudd')
print(person.name)
print(doctor.name)
print(lawyer.name)
print(give_me_a_yugo.need_a_push())