Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Output difference why?

 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15715
73
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first example, you are creating a new Thread object (line 6) and then you print out the name of that object on line 8. Note that line 7 does nothing: you call the currentThread() method but you're not doing anything with the return value, so nothing happens.

In the second example, you get the current (existing) Thread object, which is the thread that the main() method runs in, and you print its name.

The two pieces of code are not doing the same thing. Did you expect them to give the same output?
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!