Last active
June 4, 2021 14:43
-
-
Save catalunha/c02e236534bd529eeeeed02e7f4a7abd to your computer and use it in GitHub Desktop.
Resumo Dart - POO - Exemplo class Animal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Animal { | |
String nome; | |
Animal(this.nome); | |
String voz(); | |
@override | |
String toString() { | |
return '$nome ${voz()}'; | |
} | |
} | |
class Cao extends Animal { | |
int peso; | |
Cao(String nome, this.peso) : super(nome); | |
@override | |
String voz() { | |
return 'uiva'; | |
} | |
} | |
class Gato extends Animal { | |
int fofura; | |
Gato(String nome, this.fofura) : super(nome); | |
@override | |
String voz() { | |
return 'mia'; | |
} | |
} | |
void main() { | |
// Uma classe abstrata nao pode ser instanciada. E seus métodos tem q ser implementados. | |
// Animal animal = Animal(''); | |
Cao cao = Cao('sky', 30); | |
print(cao); | |
Gato gato = Gato('mimi', 100); | |
print(gato); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment