Created
April 4, 2014 02:48
-
-
Save snowdream/9967148 to your computer and use it in GitHub Desktop.
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
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"); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ java ParentChildTest
Parent()
onDraw: Parent
Parent()
ChildA()
onDraw: ChildA
Parent()
ChildB()
onDraw: ChildB
Parent()
ChildA()
onDraw: ChildA