Dev study and notes

[dart] #26 #4.7 Abstract Classes (03:53) 본문

studyLog

[dart] #26 #4.7 Abstract Classes (03:53)

devlunch4 2023. 5. 3. 06:13
반응형
abstract class Human {
  void walk();
}

enum Team { red, blue }

enum XPLevel { beginner, medium, pro }

class Player extends Human {
  String name;
  XPLevel xp;
  Team team;

  Player({
    required this.name,
    required this.xp,
    required this.team,
  });

  void walk() {
    print('I am walking');
  }

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

class Coach extends Human {
  void walk() {
    print('the coash is walking');
  }
}

void main() {
  var lunch = Player(
    name: 'lunch',
    xp: XPLevel.medium,
    team: Team.red,
  )
    ..name = 'john'
    ..xp = XPLevel.beginner
    ..team = Team.blue
    ..sayHello();
  var coach = Coach();
  coach.walk();
}

// PRINT
// >>>
// Hi my name is john
// the coash is walking
반응형

'studyLog' 카테고리의 다른 글

[dart] #28 END #4.9 Mixins (04:16)  (0) 2023.05.03
[dart] #27 #4.8 Inheritance (08:34)  (0) 2023.05.03
[dart] #25 #4.6 Enums (03:12)  (0) 2023.05.03
[dart] #24 #4.5 Cascade Notation (03:13)  (0) 2023.05.03
[dart] #23 #4.3 Named Constructors (07:28)  (0) 2023.05.03
Comments