This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Me

 
samuel ebenezer
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




Tux object will be created and calls piggy method which inturn appends string s with "Samuel" and invokes the Thread Run method. In run am directly working on String "s". Am expecting the output as "Ebenezer 0 1 2 3"...
But I got only "Ebenezer" as the output whereas the answer is 4th option.. I was stucked here. Can any one explain me this?
 
Milan Sutaria
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
samuel try using system.out.println statements to decode it urself.
i did it & found that it id because the system.out.println(s) prints the value immediately aftr starting the thread. untill this time the for loop hasn't even run once!!!
put sleep(10) in main method just before system.out.println(s) [trysystem.out.println(s+"I AM IN MAIN")]
 
subhasish nag
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Samuel,
here the method piggy(String s )is actually changing the parameter s(not the instance variable s ). So when we invoke the method it is only the copy of s and the change is only made inside the method, not on instace variable.
you can put System.out.println(s) just after the line: s=s+1 inside the method and can check.

subhasish
 
samuel ebenezer
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Milan.. I got this.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic