Skip to content

Instantly share code, notes, and snippets.

@snowdream
Created April 4, 2014 02:48
Show Gist options
  • Save snowdream/9967148 to your computer and use it in GitHub Desktop.
Save snowdream/9967148 to your computer and use it in GitHub Desktop.
public class ParentChildTest{
public static void main(String[] args){
Parent parent = new Parent();
parent.onDraw();
ChildA childA = new ChildA();
childA.onDraw();
ChildB childB = new ChildB();
childB.onDraw();
Parent parentca = new ChildA();
parentca.onDraw();
}
public static class Parent{
public Parent(){
System.out.println("Parent()");
}
public void onDraw(){
System.out.println("onDraw: Parent");
}
}
public static class ChildA extends Parent{
public ChildA(){
System.out.println("ChildA()");
}
public void onDraw(){
System.out.println("onDraw: ChildA");
}
}
public static class ChildB extends Parent{
public ChildB(){
System.out.println("ChildB()");
}
public void onDraw(){
System.out.println("onDraw: ChildB");
}
}
}
@snowdream
Copy link
Author

$ java ParentChildTest
Parent()
onDraw: Parent
Parent()
ChildA()
onDraw: ChildA
Parent()
ChildB()
onDraw: ChildB
Parent()
ChildA()
onDraw: ChildA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment