码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA 多态

时间:2015-02-17 09:11:23      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

多态是编程语言给不同的底层数据类型做相同的接口展示的一种能力。一个多态类型上的操作可以应用到其他类型的值上面

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

JAVA 多态

标签:

原文地址:http://www.cnblogs.com/liangnote/p/4294801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!