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.
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 ]
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 ]
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 ]