Dev study and notes

[dart] #27 #4.8 Inheritance (08:34) 본문

studyLog

[dart] #27 #4.8 Inheritance (08:34)

devlunch4 2023. 5. 3. 06:14
반응형
class Human {
  final String name;
  Human(this.name);
  void sayHello() {
    print('Hi, my name is $name');
  }
}

enum Team { blue, red }

class Player extends Human {
  final Team team;

  Player({
    required this.team,
    required String name,
  }) : super(name);

  @override
  void sayHello() {
    super.sayHello();
    print('and I play for ${team}');
  }
}

void main() {
  var player = Player(
    team: Team.red,
    name: 'lunch',
  );
  player.sayHello();
}

// PRINT
// >>>
// Hi, my name is lunch
// and I play for Team.red
반응형
Comments