Given: 1. public class Alpha{ 2. public static void main( string[] args ){ 3. if ( args.length == 2 ) { 4. if ( args.[0].equalsIgnoreCase(�-b�) ) 5. System.out.println( new Boolean( args[1] )); 6. } 7. } 8. } And the code is invoked by using the command: java Alpha �b TRUE What is the result? A. true B. null C. false D. Compilation fails. E. The code runs with no output. F. An exception is thrown at runtime. Answer: A Why ??
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
PETER, I have asked you before: please specify the source of these questions.
Why do you think the anwser is not choice A? Have you run the code?
Hi, What is that you did not understand in this code. The code is pretty straight forward. I am concidering that 1. The instead of was a typo. 2. The instead of was a typo.
To compile the code then true is an obvious answer. If the above assuptions are incorrect and you got the code the way it is in your post then it will result in compilation error.
-Saurabh [ September 15, 2004: Message edited by: Barry Gaunt ]
PETER CARTER
Ranch Hand
Joined: Aug 28, 2004
Posts: 70
posted
0
Sorry,but I compile fail: E:\l>javac Alpha.java Alpha.java:4: <identifier> expected if ( args.[0].equalsIgnoreCase("-b") ) ^ Alpha.java:6: ')' expected } ^ 2 errors Why I can't compile successfully? Thanks .
Adrian Marti
Greenhorn
Joined: Sep 07, 2004
Posts: 11
posted
0
args[0] not args.[0]
args is an array
hth
Adrian
Doyle Matt
Ranch Hand
Joined: Jul 05, 2004
Posts: 76
posted
0
Hi Peter,
May I suggest the following books for you to get an indepth knowledge on java.
1. Beginning Java 1.4 Ed by Horton 2. Sun Certified Programmer & Developer for Java 2 Study Guide by Kathy Sierra, Bert Bates
There are a lot of online resources namely:
1. Javaranch (of course) 2. java.sun.com (try to download the tutorial) 3. javaworld.com 4. google.com
Hope this will solve all of your problems
Cheer.
SCJP 1.4
PETER CARTER
Ranch Hand
Joined: Aug 28, 2004
Posts: 70
posted
0
Marti,
public class Alpha{ public static void main( String[] args ){ if ( args.length == 2 ) { if ( args[0].equalsIgnoreCase("-b") ) System.out.println( new Boolean( args[1] )); } } } I compile it. E:\l>java Alpha -b TURE false So C is right ,not A. Do you follow me ?