你的意思是用子类对象调用父类被覆盖的方法是吧?代码如下,另外你的代码小问题也有,帮你改啦,自己看看,你定义的函数不用返回数据,所以定义成public void 就可以
也省去return语句啦!!!!
class Fu
{
public void show()
{
System.out.print("a");
}
}
class Zi extends Fu
{
public void show()
{
System.out.print("b");
}
public void showFu()
{
super.show();//调用父类被覆盖的方法
}
}
class Run
{
public static void main(String [] args)
{
Zi z= new Zi();
z.showFu();
}
}
class Fu{
private Fu(){}
public static Fu f= new Fu();
public static Fu getFu()
{
return f;
}
}
class Zi extends Fu
{
.......
.......
.......
}
class Run
{
class Fu
{
int show()
{
System.out.print("a");
return 0;
}
}
class Zi extends Fu
{
int show()
{
System.out.print("b");
return 0;
}
}
class Run
{
public static void main(String [] args) throws Exception
{
Fu z= new Zi();
z.show(); //在这地方直接调用父类中的show()如何调用?
Fu f = (Fu)z.getClass().getSuperclass().newInstance();
f.show();
}
}