Last active
September 21, 2020 15:33
-
-
Save cybo42/6bea55df38a03628f3d23dac1e58ac46 to your computer and use it in GitHub Desktop.
Dartstuff
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
void main() { | |
Animal bob = new Kitten(); | |
bob.grow(); | |
bob.grow(); | |
bob.birthday(); | |
print(bob.speak()); | |
Animal x = new Puppy(); | |
print(bob); | |
print(x.speak()); | |
} | |
abstract class Animal { | |
int age; | |
Animal() { | |
this.age = 0; | |
print("Animal in the house"); | |
} | |
void grow() { | |
age++; | |
} | |
birthday() { | |
print("My Age is ${age}"); | |
} | |
String speak(); | |
} | |
class Kitten extends Animal { | |
@override | |
String speak() { | |
return 'Meow'; | |
} | |
} | |
class Puppy extends Animal { | |
@override | |
String speak() { | |
return 'Ruff'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment