Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads Q

 
mohamed hamdy
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because sName is local to the piggy method.
 
mohamed hamdy
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11944
212
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic