This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes setName() in Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "setName() in Threads" Watch "setName() in Threads" New topic
Author

setName() in Threads

Gajendra Kangokar
Ranch Hand

Joined: Dec 25, 2012
Posts: 72

In the below code where class extends thread,at line number 16 setName("Thread") method is called when there is no such method defined in this class.
My question is,how is the code still working with proper output.


Thanks
Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

Are you new to Java?
The method is inherited from class Thread.


Regards,
Prajakta
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41141
    
  45
extends Thread


What do you think this accomplishes?

Generally, you should not extend Thread, but implement Runnable or a similar interface: https://www.coderanch.com/how-to/java/ExtendingThreadVsImplementingRunnable


Ping & DNS - my free Android networking tools app
Gajendra Kangokar
Ranch Hand

Joined: Dec 25, 2012
Posts: 72

Are you new to Java?

yes somewhat new!!very new to Threads atleast.

What do you think this accomplishes?

i am trying to learn threads and this was just a example to learn and thanks for the usefull link
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Actually, named Threads can be helpful in debugging so this is good to explore.

Bill
 
wood burning stoves
 
subject: setName() in Threads
 
Similar Threads
isAlive()
Thread
Thread
Synchronized ?
Thread.sleep() and lock