26 lines
676 B
Python
26 lines
676 B
Python
# Heritage / Composition
|
|
# Heritage: relation "EST UN"
|
|
|
|
class Person:
|
|
def __init__(self, nom, prenom, age):
|
|
self.nom = nom
|
|
self.prenom = prenom
|
|
self.age = age
|
|
|
|
def dire_bonjour(self):
|
|
return "Bonjour tout le monde"
|
|
|
|
class Student(Person): # Heritage
|
|
def __init__(self, nom, prenom, age, domaine):
|
|
super().__init__(nom, prenom, age)
|
|
self.domaine = domaine
|
|
|
|
# override
|
|
def dire_bonjour(self):
|
|
return super().dire_bonjour() + "! Ca va?"
|
|
|
|
alice = Student('Smith', 'Alice', 19, 'Finance')
|
|
print(alice.dire_bonjour())
|
|
print(alice.__dict__)
|
|
print(isinstance(alice, Student))
|
|
print(isinstance(alice, Person)) |