Skip to content

Commit 4fb75d5

Browse files
author
Matheus
committed
Adicionada sobrescrita a métodos
1 parent 3ca127f commit 4fb75d5

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

atores.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def colidir(self, outro_ator, intervalo=1):
5757

5858

5959
class Obstaculo(Ator):
60-
pass
60+
_caracter_ativo = 'O'
6161

6262

6363
class Porco(Ator):
64-
pass
64+
_caracter_ativo = '@'
6565

6666

6767
class DuploLancamentoExcecao(Exception):

oo/pessoa.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class Pessoa:
2-
32
olhos = 2
43

54
def __init__(self, *filhos, nome=None, idade=35):
@@ -8,21 +7,29 @@ def __init__(self, *filhos, nome=None, idade=35):
87
self.filhos = list(filhos)
98

109
def cumprimentar(self):
11-
return f'Olá {id(self)}'
10+
return f'Olá, meu nome é {self.nome}'
1211

1312
@staticmethod
1413
def metodo_estatico():
1514
return 42
15+
1616
@classmethod
1717
def nome_e_atributos_de_classe(cls):
1818
return f'{cls} - olhos {cls.olhos}'
1919

20+
2021
class Homem(Pessoa):
21-
pass
22+
def cumprimentar(self):
23+
cumprimentar_da_classe_pai = super().cumprimentar()
24+
return f'{cumprimentar_da_classe_pai}. Aperto de mão'
25+
26+
class Mutante(Pessoa):
27+
olhos = 3
28+
2229

2330
if __name__ == '__main__':
24-
renzo = Homem(nome='Renzo')
25-
luciano = Pessoa(renzo, nome='Luciano')
31+
renzo = Mutante(nome='Renzo')
32+
luciano = Homem(renzo, nome='Luciano')
2633
print(Pessoa.cumprimentar(luciano))
2734
print(id(luciano))
2835
print(luciano.cumprimentar())
@@ -37,7 +44,7 @@ class Homem(Pessoa):
3744
del luciano.olhos
3845
print(luciano.__dict__)
3946
print(renzo.__dict__)
40-
Pessoa.olhos = 3
47+
4148
print(Pessoa.olhos)
4249
print(luciano.olhos)
4350
print(renzo.olhos)
@@ -48,7 +55,5 @@ class Homem(Pessoa):
4855
print(isinstance(pessoa, Pessoa))
4956
print(isinstance(pessoa, Homem))
5057
print(isinstance(renzo, Homem))
51-
52-
53-
54-
58+
print(luciano.cumprimentar())
59+
print(renzo.cumprimentar())

0 commit comments

Comments
 (0)