• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about mock test

 
VuTuan Tran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is taken from SCJP 6 study guide
1.class Fork {
2.public static void main(String[] args) {
3.if(args.length == 1 | args[1].equals("test")) {
4.System.out.println("test case");
5.} else {
6.System.out.println("production " + args[0]);
7.}
8.}
9.}
And the command-line invocation:
java Fork live2
Question : what is the result

I dont understand why the answer is
E. An exception is thrown at runtime

My logic is :at line 3 we are going to have
It is equivalent to
I know my logic is wrong but I cant figure it out. Please help me to make it clear.Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's only one parameter : live2. So only args[0] is valid.
 
VuTuan Tran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:There's only one parameter : live2. So only args[0] is valid.

Ahhhhhhh, it is my bad. Thanks for pointing out.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please always tell us what the thread is about; "question about mock test" is too vague.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic