如下面的代码
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