请问异常继承的问题? 这句话的翻译肯定有些问题。我的理解是这样的比如父类里有函数f() throws ex1那子类里不能再f() throws ex1,就是说异常不能这样传递抛出,不知道楼主认为如何? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼上说的这样可以呀?如下:class ThrowException1{public int x; public void throw1() throws ArithmeticException {x=0; x=3/x; x=1; System.out.println("x="+x); }}public class ThrowException extends ThrowException1{ public void throw1() throws ArithmeticException {x=0; x=3/x; x=1; System.out.println("x="+x); } public static void main(String[] args) { ThrowException t = new ThrowException(); try{ t.throw1(); } catch (Exception e){System.out.println("begin!!!!!!") e.printStackTrace(); System.out.println("get message="+e.getMessage()); } } }编译运行都正常呀? sorry是我的理解有问题了。是这样的,如果父类函数不抛出异常,子类也不能抛出。如果父类函数抛出异常,那子类只能抛出同样的异常,就是说只有我写的那种情况才是没错误的。ft理解有问题,sorry 今天的面试题目 删除按钮,按钮的图片还在 CTabFolder 问题 每隔1秒鐘就去檢查一個變量,當那變量變為0時,就println(“end”)怎麼寫呢? 请指教下,刚开始看java 用java语言如何实现以下文件操作的功能 java编译时出错,我应该把java放在一个固定的目录下,还是任何地方都可以? 求救:哪位大侠有能把 .wav 变成 .au 的转换程序? JAVA程序里不能正确显示汉字 关于读取A服务器到B数据库的问题 请版主,各位高手帮忙!!急!! 散分!!郁闷,本来是三颗星的,结果换了一下名称,竟然少了两颗星~~~~抗议~~up着有分!!!!!!!!!!!!!!!
如下:class ThrowException1
{public int x;
public void throw1() throws ArithmeticException
{x=0;
x=3/x;
x=1;
System.out.println("x="+x);
}
}
public class ThrowException extends ThrowException1
{ public void throw1() throws ArithmeticException
{x=0;
x=3/x;
x=1;
System.out.println("x="+x);
}
public static void main(String[] args)
{ ThrowException t = new ThrowException();
try{
t.throw1(); }
catch (Exception e){System.out.println("begin!!!!!!")
e.printStackTrace();
System.out.println("get message="+e.getMessage());
}
}
}
编译运行都正常呀?