Created with <3 with dartpad.dev.
Last active
July 16, 2023 07:43
-
-
Save kmkkkp/0c0da1aa3df2aec283a167de9b3a4087 to your computer and use it in GitHub Desktop.
Inheritance
This file contains 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 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.name}'); | |
} | |
} | |
void main() { | |
var player = Player( | |
team: Team.red, | |
name: 'nico', | |
); | |
player.sayHello(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment