香港的期货公司

您现在的位置:股票配资 > 机械设备 >

 JAVA 多态

发布时间: 2015-02-17 14:52


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

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


皇中设备厂
配资开户 我们