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

a.process(); // 这一句为什么编译异常呢?

2012-02-21 
a.process()// 这一句为什么编译错误呢? 请指教class A{void process()throws Exception{throw new Excep

a.process(); // 这一句为什么编译错误呢? 请指教
class A{
void process()throws Exception{
throw new Exception();
}
}
class b extends A{
void process(int a){
System.out.println("B");
}
}
public class J{
public static void main(String[] args){
A a=new b();
a.process(); // 这一句为什么编译错误呢? 请指教
}
}
a.process(); // 这一句为什么编译错误呢? 请指教


[解决办法]
没有方法重写 
不能发生多态。
a调不到 b类中 process(int a );
a实际调的是 A类中的process()方法。
所以要抛出异常。

热点排行