`

java的静态方法和非静态方法

    博客分类:
  • 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";
	}
}

 

 

输出为:

M
NN
1
2

 

 

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics