Created
March 27, 2020 20:41
-
-
Save nunomazer/ecc96588f887235d3bcb56795f0839ed to your computer and use it in GitHub Desktop.
Exemplo construtor em Dart
This file contains hidden or 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
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