Skip to content

Instantly share code, notes, and snippets.

@catalunha
Last active June 4, 2021 14:43
Show Gist options
  • Save catalunha/c02e236534bd529eeeeed02e7f4a7abd to your computer and use it in GitHub Desktop.
Save catalunha/c02e236534bd529eeeeed02e7f4a7abd to your computer and use it in GitHub Desktop.
Resumo Dart - POO - Exemplo class Animal
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