Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created August 30, 2023 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/b27a8f7b62ffdb255a9a6d1415a3e690 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/b27a8f7b62ffdb255a9a6d1415a3e690 to your computer and use it in GitHub Desktop.
resonating-aqueduct-1695

resonating-aqueduct-1695

Created with <3 with dartpad.dev.

void main() {
Dolphin flipper = Dolphin('bottlenose');
print('Flipper is a ${flipper.type} dolphin.');
flipper.eat('crab');
flipper.eat('shark');
flipper.swim();
Kangaroo skippy = Kangaroo('Western Grey');
print('Skippy is a ${skippy.breed} kangaroo.');
skippy.eat((type: 'cow', isPlant: false));
skippy.hop();
skippy.eat((type: 'grass', isPlant: true));
}
class Animal {
Animal();
eat(var food){
print('Thanks for the $food');
}
}
class Dolphin extends Animal {
late String type;
List<String> foodTypes = ['crab', 'octopus', 'herring'];
Dolphin(this.type);
@override
eat(var food){
if(foodTypes.contains(food)){
print('Thanks for the $food');
}else{
print('Yuck. I cannot eat $food');
}
}
swim() {
print('Splish. Splash.');
}
}
class Kangaroo extends Animal {
late String breed;
Kangaroo(this.breed);
@override
eat(var food){
// expects (type: '', isPlant: true)
if(food.isPlant){
print('Yum! ${food.type}!');
}else{
print('I only eat plants');
}
}
hop(){
print('hop hop hop');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment