Created with <3 with dartpad.dev.
Created
August 30, 2023 18:15
-
-
Save prof3ssorSt3v3/b27a8f7b62ffdb255a9a6d1415a3e690 to your computer and use it in GitHub Desktop.
resonating-aqueduct-1695
This file contains hidden or 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
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