Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command Line Invocation

 
Chadd Franck
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is from Sun Certified Programmer for Java 6 Study Guide, Page 320,


And the command-line invocation:
java Fork live2

What is the result?

A. test case
B. production live2
C. test case live2
D. Compilation fails
E. An exception is thrown at runtime

Answer:
E is correct. Because the short circuit (||) is not used, both operands are evaluated. Since args[1] is past the args array bounds, an ArrayIndexOutOfBoundsException is thrown. A, B, C, and D are incorrect based on the above. (Objective 7.6)

Why isn't args[1] = live2? therefore not outofbounds?
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why isn't args[1] = live2? therefore not outofbounds?


Arrays are zero based -- so the first element is args[0]. Hence, args[0] is live2, and args[1] is out of bounds.

Henry
 
Chadd Franck
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hehe yea I see it, I was thinking that Fork was an arg for some reason, I can see that it is the name of the class (G)...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic