Dev study and notes

[dart] #21 #4.1 Constructors (03:58) 본문

studyLog

[dart] #21 #4.1 Constructors (03:58)

devlunch4 2023. 5. 3. 06:06
반응형
class Player {
    final String name;
    int xp = 9999;

    Player(this.name, this.xp);

    void sayHello() {
    print("Hi my name is $name");
    }
}

void main() {
    var player = Player('lunch', 9999);
    print(player.name);
    player.sayHello();
    var player2 = Player('lunch2', 2222);
    player2.sayHello();
}

// PRINT
// >>>
// lunch
// Hi my name is lunch
// Hi my name is lunch2
반응형
Comments