日期:2014-05-20  浏览次数:20655 次

一个关于继承的问题 很简单
class Good{
void f1(){
System.out.println("f1()");
}
void f1(int i){
System.out.println("f1(int i)");
}
void f1(double i){
System.out.println("f1(double i)");
}
}
class Good1 extends Good{
void f1(){
System.out.println("导出类的f1()");
super.f1();
f1(1);
f1(1.4);
}


}
public class P713 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
}
Good1 g=new Good1();
g.f1();
}

帮小弟看下这个错在哪里 为什么g.f1();会出错

------解决方案--------------------
把代码:
Good1 g=new Good1(); 
g.f1();
放到main()方法里就好了;
输出:
导出类的f1()
f1()
f1(int i)
f1(double i)

------解决方案--------------------
你把语句放在了方法的外面能不出错吗?


Good1 g=new Good1(); 
g.f1();
或者 
g.f1();
放到一个方法中或放到mian函数中