• 2022-05-28
    阅读下列代码,下面哪个选项是正确的( )public class TestException{public static void main(String []args) throws Exception{ if(args[0]=="123") //命令行输入参数123 throw new IOException(); }}
    A: 程序编译正确,命令行输入参数123,抛出异常
    B: 程序语法错误
    C: 程序编译错误,
    D: 程序编译正确,没有输出结果
  • D

    举一反三

    内容

    • 0

      下列叙述正确的是( ) public class E { public static void main(String args[]) { String s1=args[1]; String s2=args[2]; String s3=args[3]; System.out.println(s3); } } A: 程序编译出现错误 B: 无编译错误,在命令行执行程序“java E I love this game”,程序输出this C: 无编译错误,在命令行执行程序“java E let us go”,程序无运行异常 D: 无编译错误,在命令行执行程序“java E 0 1 2 3 4 5 6 7 8 9”,程序输出3

    • 1

      阅读下面的程序,分析代码是否能编译通过。如果能编译通过,请列出运行的结果;如果不能编译通过,请说明原因。class RunHandler {public void run() {System.out.println("run");}}public class Read01 {public static void main(String [] args) {Thread t = new Thread(new RunHandler( ));t.start( );}}

    • 2

      阅读下面的程序,分析代码是否能编译通过,如果能编译通过,选正确。如果不能编译通过,选错误。 public class A extends Thread{ protected void run() { System.out.println("thisisrun()"); } public static void main(String[] args) { A a = new A(); a.start(); } }

    • 3

      interface A{ void x(); } class B implements A{ public void x(){} public void y(){} } class C extends B{ public void x(){System.out.println("C");} } public class Test{ public static void main(String args[]){ B b=new B(); B c=new C(); b.x(); c.y(); } } A: 程序运行错误 B: 程序没有输出结果 C: 程序输出C。 D: class B implements A 编译错误 E: c.y();编译错误

    • 4

      阅读下面代码段:public class Demo{public static void main (String[] args){int[] arr = new int [10];System.out.println(arr[1]);}}执行结果正确的说法是( ) A: 编译时将产生错误 B: 编译时正确,运行时将产生错误 C: 输出0 D: 输出空