更多"考虑下列Java代码:  class A&ensp"的相关试题:
[单项选择] 考虑下列Java代码: Classc A{ Public static void main(String []args){ Try{ System.out.println(“hello,world”) } } } 其中错误的是()。
A. 没有catch或finally块
B. 没有抛出异常的代码不能出现在try代码块内
C. 如果没有catch块而使用try,main()会总是抛出异常.
D. class A 没有throws IOException
[单项选择] 分析下列java代码 Class A{ Public static void main(String[] args){ Method(); } Static void method(){ try{ System.out.println(“hello”) }finally{ System.out.println(“good-bye”); } } } 编译运行后,输出结果是()
A. “hello”
B. “good-bye”
C. “hello”“good-bye”
D. 代码不能编译
[单项选择] 研究下面的Java代码: public class testException{ public static void main(String args[]){ int a[]={0,1,2,3,4}; int sum=0; try{ for(int i=1;i<6;i++) sum=sum+a[i]; System.out.println("sum="+sum); } catch(ArrayIndexOutOfBoundsException ){ System.out.println("数组越界"); } finally{ System.out.println("程序结束");} } } 输出结果将是()。
A. 10 数组越界 程序结束
B. 10 程序结束
C. 数组越界 程序结束
D. 程序结束
[单项选择] class java { public static void main(String [] java) { for (int Java = 1; Java 〈 java.length; Java++) System.out.print("java "); } } 和命令行: java java java java java 结果为:()
A. java
B. java java
C. java java java
D. 编译失败
[单项选择] public class Pet{ public void speak(){ System.out.print(“ Pet ”); } } public class Cat extends Pet{ public void speak(){ System.out.print(“ Cat ”); } } public class Dog extends Pet{ public void speak(){ System.out.print(“ Dog ”); } } 执行代码 Pet[] p = {new Cat(),new Dog(),new Pet()}; for(int i=0;i〈p.length;i++) p[i].speak(); 后输出的内容是哪项?()
A. Pet Pet Pet
B. Cat Cat Cat
C. Cat Dog Pet
D. Cat Dog Dog
[单项选择] public class X { public static void main(String [] args) { try { badMethod(); System.out.print(“A”); } catch (Exception ex) { System.out.print(“B”); } finally { System.out.print(“C”); } System.out.print(“D”); } public static void badMethod() {} } What is the result?()
A. AC
B. BD
C. ACD
D. ABCD
E. Compilation fails.
[单项选择] public class TestApp{ public static void main(String[] args){ try{ String myname = null; if(myname.length()>2) System.out.print(“1”); }catch(NullPointerException e){ System.out.print(“2”); } } } 上述程序运行后的输出是哪项?()
A. 1
B. 12
C. 21
D. 2
[单项选择] public class test( public static void main(string[]args){ string foo = args [1]; string foo = args [2]; string foo = args [3]; } ) And command line invocation: Java Test red green blue What is the result?()
A. Baz has the value of “”
B. Baz has the value of null
C. Baz has the value of “red”
D. Baz has the value of “blue”
E. Bax has the value of “green”
F. The program throws an exception.
[单项选择] public class Demo{ public static void main(String[] args){ List al = new ArrayList(); al.add(“1”); al.add(“2”); al.add(“2”); al.add(“3”); System.out.println(al); } } 上述程序执行后的输出是哪项?()
A. [1,2,3]
B. [1,2,2,3]
C. [1,2,3,3]
D. [2,1,3,2]
[单项选择] public class Test{ public static void main( String[] argv ){ // insert statement here } } Which statement, inserted at line 3, produces the following output?() Exception in thread “main” java.lang.AssertionError: true at Test.main(Test.java:3)
A. assert true;
B. assert false;
C. assert false : true;
D. assert false == true;
E. assert false: false;
[单项选择] public class EqTest{() Public static void main(String args[]) EqTest e=new EqTest(); } EqTest(){ String s=”Java”; String s2=”java”; //在这儿放置测试代码 {Systrm.out.println(“相等”); Else{System.out.println(“不相等”)} } } 在上面的java代码的注释行位置,放置()测试代码能输出“相等”结果
A. if(s==s2)
B. if(s.equals(s2))
C. if(s.equalsIgnoreCase(s2))
D. if(s.noCaseMatch(s2))