This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Q Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads Q" Watch "Threads Q" New topic

Threads Q

mohamed hamdy
Ranch Hand

Joined: Feb 13, 2003
Posts: 72
look to this question:

1) Compile time error
2) Compilation and output of "vandeleur wiggy"
3) Compilation and output of "vandeleur wiggy 0 1 2 3"
4) Compilation and probably output of "vandelur" but possible output of "vandeleur 0 1 2 3"
the answer is 4.
why "wiggy" is execluded?
i think that there are five possibilities for the output.
[ Jess added whitespace to make the code a bit easier to read ]
[ April 05, 2003: Message edited by: Jessica Sant ]
Martin Smith

Joined: Apr 05, 2003
Posts: 22
because sName is local to the piggy method.
mohamed hamdy
Ranch Hand

Joined: Feb 13, 2003
Posts: 72
thanks Martin,
because the method creates a new String object that's not referrenced by the calss member sName ,
but what about the four possibilities of "0",
"0 1", "0 1 2", or "0 1 2 3" being concatenated to sName.
[ April 05, 2003: Message edited by: mohamed hamdy ]
preeti khane
Ranch Hand

Joined: Mar 12, 2003
Posts: 93
Shouldn't the answers have choice with vandeleur 0, vandeleur 0 1, vandeleur 0 1 2, vandeleur 0 1 2 3
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11730

Mohamed & Preeti,
You are right, there could be other possible answers, however in this (and in the real exam) you should not get caught up in what else is possible - only which of the answers given could be correct
Option 1 (Compile time error) is wrong - there is no reason the program will not compile.
Option 2: (output including "wiggy") - as previously mentioned, wiggy is only appended to a local String in the piggy method, and is not used within that method. All other methods refer to the global String, which starts as "vandeleur" and never has "wiggy" appended to it. Therefore this is wrong.
Option 3 - Compilation and output of "vandeleur wiggy 0 1 2 3". As with the previous option, this will never occur because the global String never contains the "wiggy". Even without that, you could not be guaranteed that 0 1 2 3 will be output
Option 4) Compilation and probably output of "vandelur" but possible output of "vandeleur 0 1 2 3". Yes this answer is correct. It is probable that you will only see an output of "vandelur", however it is possible that you could see "vandelur 0 1 2 3".
Therefore for this mock question, and for the real exam, answer 4 is correct.
You are both correct that there could be other possible outcomes of running this, however these other possibilities do not invalidate option 4.
[ April 07, 2003: Message edited by: Andrew Monkhouse ]

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Have you checked out Aspose?
subject: Threads Q
It's not a secret anymore!