Last active
February 10, 2016 00:33
-
-
Save guoguo12/017cad046b7f6a458b58 to your computer and use it in GitHub Desktop.
To run, download and run "javac *.java && java Main".
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 { | |
void bark(Animal a) { | |
System.out.println("bark(Animal a) in Animal"); | |
}; | |
void bark(Dog d) { | |
System.out.println("bark(Dog a) in Animal"); | |
}; | |
} |
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 Dog extends Animal { | |
/* Try commenting this method out and see what happens! */ | |
void bark(Animal a) { | |
System.out.println("bark(Animal a) in Dog"); | |
}; | |
void bark(Dog d) { | |
System.out.println("bark(Dog d) in Dog"); | |
}; | |
} |
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 Main { | |
public static void main(String[] args) { | |
Animal a = new Dog(); | |
a.bark(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment