Created
December 13, 2017 19:30
-
-
Save penut85420/c63e56f748bb0b493e22a0142d5419e6 to your computer and use it in GitHub Desktop.
A note of Overriding.
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
class Animal { | |
public String talk() { | |
return "Hi"; | |
} | |
} | |
class Dog extends Animal { | |
public String talk() { | |
return "Woof!"; | |
} | |
} | |
static void main(String[] args) { | |
Animal a = new Dog(); | |
a.talk(); // return "Woof!" not "hi" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment