jQuery in Action, 2nd edition*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "setName() in Threads" Watch "setName() in Threads" New topic

setName() in Threads

Gajendra Kangokar
Ranch Hand

Joined: Dec 25, 2012
Posts: 71

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.

Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

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

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41065
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: 71

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

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

jQuery in Action, 2nd edition
subject: setName() in Threads
Similar Threads
Synchronized ?
Thread.sleep() and lock