首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java的静态方法跟非静态方法

2012-12-18 
java的静态方法和非静态方法public class Test{public static void main(String[] args){M m new N()Sy

java的静态方法和非静态方法
public class Test  
{  
    public static void main(String[] args)  
    {  
        M m = new N();  
          
        System.out.println(m.getName());  
          
        System.out.println(m.getValue());  
          
        if(m instanceof N)  
        {  
            System.out.println("1");  
        }  
          
        if(m instanceof M)  
        {  
            System.out.println("2");  
        }  
    }  
}  
 
class M  
{  
    public static String getName()  
    {  
        return "M";  
    }  
      
    public String getValue()  
    {  
        return "MM";  
    }  
}  
 
class N extends M  
{  
    public static String getName()  
    {  
        return "N";  
    }  
      
    public String getValue()  
    {  
        return "NN";  
    }  

热点排行