当编译并且运行下面程序时会出现什么结果?
public class ThrowsDemo{
static void throwMethod() {
System.out.print("Inside throwMethod");
throw new IOException("demo");
}
public static void main(String [] args){
try{
throwMethod();
}catch(IOException e){
System.out.println("Cauht"+e);
}
}
}
public class ThrowsDemo{
static void throwMethod() {
System.out.print("Inside throwMethod");
throw new IOException("demo");
}
public static void main(String [] args){
try{
throwMethod();
}catch(IOException e){
System.out.println("Cauht"+e);
}
}
}
举一反三
- 请说出下列程序的输出结果_____________,_____________。import java.io.IOException;public class E {public static void main(String args[]){try { methodA();}catch(IOException e){System.out.print("你好");return;}finally {System.out.println("thanks");}}public static void methodA() throws IOException{throw new IOException();}}
- 给出下列程序的输出结果。import java.io.IOException;public class E {public static void main(String args[]){int m =10;try {methodA();m = 100;}catch(IOException e){m = 1000;}System.out.println(m);}public static void methodA() throws IOException{throw new IOException();}}
- 中国大学MOOC: 下列代码中构造方法的返回类型是()public class Village { Village () { System .out .println(“hiding in Village”) ; } public static void main( String args [ ]) { Village c =new Village ( ) ;}class Village { public static void main( String args [ ]) { Village c =new Village ( ) ; } Village () { System .out .println(“hiding in Village”) ; } }
- (9-4)请根据提示补全程序空白处,使程序能够正确运行。 public class Demo { static void show() throws ① { System.out.println("抛出异常!"); throw new IllegalAccessException("一个异常"); } public static void main(String []args) { try { show(); }catch( ② e ) { e.printStackTrace(); } } }
- (7-1)以下程序的运行结果是( )。 class A{ A(){ System.out.print(10); } } public class Demo extends A { public static void main(String[] args) { new A(); new Demo(); } }