(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 Demo {
static void show() throws ① {
System.out.println("抛出异常!");
throw new IllegalAccessException("一个异常");
}
public static void main(String []args) {
try {
show();
}catch( ② e ) {
e.printStackTrace();
}
}
}
举一反三
- 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) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }
- (8-1)根据提示补全程序空白处,使程序能够正确运行。 1. 定义类Base package cn.edu.jsu; public class Base { ① void show() { System.out.println("你好,中国!"); } } 2. 定义测试类Demo package per.cn.edu.jsu; import cn.edu.jsu.Base; public class Demo { public static void main(String[] args) { Base.show(); } }
- 下列程序运行结果是( ) public class Demo { public static void main(String[] args) { Demo demo = new Demo(); demo.show(new Car() { public void run() { System.out.println("demo run"); } }); } public void show(Car c) { c.run(); } }abstract class Car { public void run() { System.out.println("car run..."); } }
- 下列程序运行结果是( ) 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"); } }