JAVA 多态
多态是编程语言给不同的底层数据类型做相同的接口展示的一种能力。一个多态类型上的操作可以应用到其他类型的值上面
package peoplePack; public class JavaApp { public static void main(String[] args) { Young y = new Young(); y.testInstanceMethod(); People p = new Young(); p.testInstanceMethod(); People.testClassMethod(); Young.testClassMethod(); } } class People { public static void testClassMethod(){ System.out.println("Static Method in People"); } public void testInstanceMethod(){ System.out.println("Instance Method in People"); } } class Young extends People{ public static void testClassMethod(){ System.out.println("The static method in Young"); } public void testInstanceMethod(){ System.out.println("The instance method in Young"); } }
Output:
The instance method in Young
The instance method in Young
Static Method in People
The static method in Young
Reference
http://docs.oracle.com/javase/tutorial/java/IandI/override.html
posted on 2015-02-17 09:01 sdet_liang 阅读(198) 评论(0) 编辑 收藏 举报