Skip to content

Instantly share code, notes, and snippets.

@cybo42
Last active September 21, 2020 15:33
Show Gist options
  • Save cybo42/6bea55df38a03628f3d23dac1e58ac46 to your computer and use it in GitHub Desktop.
Save cybo42/6bea55df38a03628f3d23dac1e58ac46 to your computer and use it in GitHub Desktop.
Dartstuff
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