1. public class test(
2. public static void main(string[]args){
3. string foo = args [1];
4. string foo = args [2];
5. string foo = args [3];
6. }
7. )
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”
F. The code does not compile.
G. The program throws an exception.
答案是什么啊?为什么?

解决方案 »

  1.   

    命令行:Java Test red green blue
    有三个参数red green blue,但是从0开始到2
    所有异常。
      

  2.   

    这个能通过编译吗?
     String foo = args [1];
     String foo = args [2];
     String foo = args [3];即使是这样?
      

  3.   

    Java Test red green blue
    args [3]会出错
      

  4.   

    foo 被定义了三次,不冲突?
      

  5.   

    这个能通过编译吗?
     String foo = args [1];
     String foo = args [2];
     String foo = args [3];即使是这样?
    =================================
    呵呵
    他的string都应该变成String
    第一对()应该换成{}
      

  6.   

    这个能通过编译吗?
     String foo = args [1];
     String foo = args [2];
     String foo = args [3];即使是这样?
    =================================
    呵呵
    他的string都应该变成String
    第一对()应该换成{}
    -------------------------------
    都写成String ,foo就被定义了三次,
    这程序能编译吗?
      

  7.   

    我选F
    因为,前面的那个foo变量已经定义了,后面的不可以再使用
      

  8.   

    肯定编译不了咯
    string,大小写
    foo,重复定义
      

  9.   

    选F,
    C:\>javac test.java
    test.java:1: 需要 '{'
    public class test(
                     ^
    test.java:8: 需要 '}'
    )
     ^
    2 错误
      

  10.   

    public class test{
    public static void main(String[]args){
    String foo = args [1];
    foo = args [2];
    foo = args [3];
    }
    }
    这样通过编译,但是运行异常,数组越界
    改动楼主程序处:
    1.test() -->test{}
    2.string -- String
    3.去掉两个String
      

  11.   

    看一眼就知道不能变异通过,首先最明显的错误,是foo变量重复定义,其次String写成了string,还有类定义的{}写成了(),就算后两个是些错了,第一个应该不是些错了,很多人选择抛出异常,真不知道是怎么考虑的。
      

  12.   

    F. The code does not compile.
      

  13.   

    1:
    如果你的题目没写错
    那答案是 F。2:
    如果题目的本意是没有任何错误
    而是印刷错误那得找印刷厂
    若是默认着印刷错误
    照着错误选答案还是  F3:
    除去上面的两种情况而是SUN出题本来就着这个原题的话
    答案还是选 F
      

  14.   

    这个叫RUNNING EXCEPTION 而不是COMPILE EXCEPTION.编译可以通过,但是运行时候错误,数组越界错误,大概是INDEXOUTOFBOUNDSEXCEPTION吧.类似的还有,String a = "ABCDE"   String b = a.subString(0,6)也是RUNNING EXCEPTION.建议楼主详细学习JAVA里面的异常分类.不难,只是不学就不知道的东西而已.
      

  15.   

    不能编译......
    有错误啊
    string foo=args[2]; ..
    重复定义..............
      

  16.   

    假如大小写没有问题 还是一个Runtime Exception 
    ArrayIndexOutOfBondsException
    因为String args[]是从0开始计算的,
    他的长度在本例是3,index不能取3
      

  17.   

    SUN 认证考试的 
    贴代码的时候认真点 呵呵
      

  18.   

    报错
    java Test...?
    应该是java test...吧?
    大小写不对
    大家不要想得太远了
    问题就在眼前