forked from DarkMemem/PythonIntro09
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polimorhpism.py
58 lines (43 loc) · 1.33 KB
/
polimorhpism.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
class Person:
def __init__(self, name, age):
self.__name = name
self.__age = age
# def __set_name(self, name):
# self.__name = name
#
# def __get_name(self):
# return self.__name
@property
def name(self):
return self.__name
@name.setter
def name(self, name):
self.__name = name
def set_age(self, age):
if 0 < age < 100:
self.__age = age
def display(self):
print('Имя:', self.__name, '\tВозраст:', self.__age)
# name = property(__get_name, __set_name)
class Employee(Person):
def __init__(self, name, age, company):
super().__init__(name, age)
self.__company = company
def display(self):
super().display()
print('Компания:', self.__company)
class Student(Person):
def __init__(self, name, age, university):
super().__init__(name, age)
self.__university = university
def display(self):
print('Студент:', self.__name, 'учится в универе:', self.__university)
# people = [Person('Tom', 23), Employee('Bob', 35, 'Google'), Student('Sam', 19, 'Harvard')]
# for person in people:
# person.display()
# print()
person = Person('Tom', 23)
person.display()
# person.set_name('Tim')
person.name = 'Tim'
print(person.name)