Skip to content

Instantly share code, notes, and snippets.

@nunomazer
Created March 27, 2020 20:41
Show Gist options
  • Save nunomazer/ecc96588f887235d3bcb56795f0839ed to your computer and use it in GitHub Desktop.
Save nunomazer/ecc96588f887235d3bcb56795f0839ed to your computer and use it in GitHub Desktop.
Exemplo construtor em Dart
class Pessoa {
// atributos
String nome;
int idade;
// construtor
Pessoa (String nome, {int idade}) {
this.nome = nome;
this.idade = idade;
}
// métodos
void cumprimentar(String nome) {
print ("Olá " + nome + " me chamo " + this.nome);
print ("Minha idade é " + (this.idade ?? "indefinida").toString());
}
}
void main() {
Pessoa p = new Pessoa("Ademir");
p.cumprimentar("Mario");
Pessoa m = new Pessoa("Marcos", idade: 33);
m.cumprimentar("Joana");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment