Created
November 24, 2021 00:37
-
-
Save felipecastrosales/905da6a00232634efe8b83d13427fcca to your computer and use it in GitHub Desktop.
POO - Static
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
// 1. Sem static: consultamos através da instância da classe | |
// 2. Com static: consultamos diretamente pela classe | |
void main() { | |
// 1. | |
var pessoa1 = Pessoa1(); | |
print(pessoa1.escola); | |
print(pessoa1.estudar()); | |
// 2. | |
//var pessoa2 = Pessoa2(); | |
print(Pessoa2.escola); | |
print(Pessoa2.estudar()); | |
} | |
// 1. | |
class Pessoa1 { | |
String escola = 'Rocketseat'; | |
String estudar() => 'Estou estudando na $escola'; | |
} | |
// 2. | |
class Pessoa2 { | |
static String escola = 'Rocketseat'; | |
static String estudar() => 'Estou estudando na $escola'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment