Skip to content

Instantly share code, notes, and snippets.

@Zhangerr
Created February 16, 2015 23:10
Show Gist options
  • Save Zhangerr/2971986ccf948b79db59 to your computer and use it in GitHub Desktop.
Save Zhangerr/2971986ccf948b79db59 to your computer and use it in GitHub Desktop.
:( inheritance hell
/**
* Created by azhang on 2/16/15.
*/
class test {
public static void main(String[] args) {
Animal fido = new Dog();
fido.speak(fido);
fido.speak((Dog) fido);
((Dog) fido).speak(fido);
((Dog) fido).speak((Dog) fido);
fido.beg(fido);
((Dog) fido).beg(fido);
fido.trick((Dog) fido);
((Dog) fido).trick((Dog) fido);
}
}
class Animal {
public void speak(Animal x) {
System.out.println("can i even speak");
}
public void beg(Animal x) {
System.out.println("im begging u human");
}
public void trick(Dog x) {
System.out.println("nope");
}
}
class Dog extends Animal{
public void speak(Dog y) {
System.out.println("woof");
}
public void beg(Animal y) {
System.out.println("treat plz :(");
}
public void trick(Dog x) {
System.out.println("*rolls over and plays dead*");
}
}
class Doge extends Dog {
public void speak(Doge g) {
System.out.println("MUCH WOW");
}
public void beg(Animal x) {
System.out.println("PLSSSSSSS");
}
public void trick(Dog z) {
System.out.println("SUCH JAVA ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment