What is the minimal list of exception classes that the overriding method f() in the following code must declare in its throws clause before the code will compile correctly?
class A{
//InterruptedException is a direct subclass of Exception.
void f() throws ArithmeticException, InterruptedException{
div(5,5);
}
int div(int i, int j)throws ArithmeticException{
return i/j;
}
}
public class MyClass extends A{
void f()/*throws [list of exceptions]*/{
try{
div(5,0);
}catch(ArithmeticException e){
return;
`}
throw new RuntimeException("ArithmeticException was expected");
}
}
class A{
//InterruptedException is a direct subclass of Exception.
void f() throws ArithmeticException, InterruptedException{
div(5,5);
}
int div(int i, int j)throws ArithmeticException{
return i/j;
}
}
public class MyClass extends A{
void f()/*throws [list of exceptions]*/{
try{
div(5,0);
}catch(ArithmeticException e){
return;
`}
throw new RuntimeException("ArithmeticException was expected");
}
}
解决方案 »
- Java刷屏函数
- 正则表达式问题
- JDK1.3中去空格的函数是???????
- FTP 的 LIST 命令获取文件信息,就是没有年份,怎么得到???
- 路过的进来看看呗,JTextField的相关问题。。。
- 请帮忙看看下面这段代码哪个地方有问题
- 如何在jbuilder中使用database连接到ms sqlserver
- **********谁能给我一分需求文档?我想练练uml和Java***********
- 请问大虾个人开发JAVA基本软硬件是什么?需要多少银子?????????给分!!
- 用Java 的socket实现客户端的功能
- 关于log4j如何只输出特定包log的问题?
- 关于绝对路径的问题,急!!!
你再试下这样改 : void f()throws RuntimeException
//InterruptedException is a direct subclass of Exception.
void f() throws ArithmeticException, InterruptedException{
div(5,5);
}
int div(int i, int j)throws ArithmeticException{
return i/j;
}
}
public class ExceptionTest extends A{
void f()/*throws [list of exceptions]*/{
System.out.println("----begin----");
try{
div(5,0);
}catch(ArithmeticException e){
//return;
e.printStackTrace();
}
System.out.println("----end----");
//throw new RuntimeException("ArithmeticException was expected");
}
public static void main(String[] args){
ExceptionTest test = new ExceptionTest();
test.f();
}
}