class MyException extends (1) {
}
public class Demo {
public static void main(String[] args) {
try {
show();
} catch ( (2) e) {
e.printStackTrace();
}
}
public static void show() (3) MyException {
throw new MyException();
}
以上程序,创建了一个自定义异常(编译异常),请补全空白处代码
}
public class Demo {
public static void main(String[] args) {
try {
show();
} catch ( (2) e) {
e.printStackTrace();
}
}
public static void show() (3) MyException {
throw new MyException();
}
以上程序,创建了一个自定义异常(编译异常),请补全空白处代码
举一反三
- (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(); } } }
- 智慧职教: 下列程序运行后输出的结果是___________。 public class MyException { public static void main (String[] args) { try{ throw new Throwable() ; } catch (Throwable e) { System. out. print (e. getMessage()) ; } } }
- Java中,自定义异常代码( )。 A: public class MyException implents Exception{ } B: class MyException extends Throwable{ } C: class MyException { } D: class MyException extends Exception{ }
- 下列程序运行结果是 public class Demo { public static void main(String[] args) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }
- 定义类Block和类Demo,运行Demo的输出结果是。 class Block{ {//代码1 System.out.print("1"); } static{//代码2 System.out.print("2"); } {//代码3 System.out.print("3"); } public Block() {//代码4 System.out.print("4"); } static void show() {//代码5 System.out.print("5"); } static {//代码6 System.out.print("6"); } } //定义测试类Demo public class Demo { public static void main(String[] args) { new Block().show(); new Block() } }