This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes question about mock test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "question about mock test" Watch "question about mock test" New topic
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: 14687
    
  16

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: 38044
    
  22
Please always tell us what the thread is about; "question about mock test" is too vague.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about mock test
 
Similar Threads
Command Line Invocation
NoSuchMethodError:main
question about Array index - ojective 7.6 on K&B SCJP book
cloning, equals() - not understanding the behaviour
K&B doubt(unofficial errata) Moderators,Please keep this thread on the top so all to see and add