Skip to content

Instantly share code, notes, and snippets.

@penut85420
Created December 13, 2017 19:15
Show Gist options
  • Save penut85420/cf410eedeef939ee38c6e77f1bb882eb to your computer and use it in GitHub Desktop.
Save penut85420/cf410eedeef939ee38c6e77f1bb882eb to your computer and use it in GitHub Desktop.
A note of Polymorphism.
abstract class Animal {
abstract String talk();
}
class Cat extends Animal {
String talk() {
return "Meow!";
}
}
class Dog extends Animal {
String talk() {
return "Woof!";
}
}
static void doTalk(final Animal a) {
println(a.talk());
}
static void main(String[] args) {
doTalk(new Cat());
doTalk(new Dog());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment