| Author |
question about mock test
|
VuTuan Tran
Greenhorn
Joined: Oct 21, 2010
Posts: 14
|
|
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
Joined: Nov 24, 2005
Posts: 14670
|
|
|
There's only one parameter : live2. So only args[0] is valid.
|
[My Blog]
All roads lead to JavaRanch
|
 |
VuTuan Tran
Greenhorn
Joined: Oct 21, 2010
Posts: 14
|
|
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
Joined: Oct 13, 2005
Posts: 32644
|
|
|
Please always tell us what the thread is about; "question about mock test" is too vague.
|
 |
 |
|
|
subject: question about mock test
|
|
|