• Post Reply Bookmark Topic Watch Topic
  • New Topic

runnable

 
yasir badshah
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is runnable class & what it's work tell me.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yasir,
Runnable isn't a class, its an interface with just one method:

The class Thread implements Runnable, but its run method doesn't do anything so you have to overload it if you extend Thread and want to do some work in a separate thread. Most of the time programmers choose to implement the Runnable interface since that allows them to extend a different more appropriate class for the type of work they are doing. This works fine because the Thread class has a constructor which takes a Runnable as a parameter. After the Thread object is constructed then all you have to do is call its start() method and your Runnable is off and running (sorry for the pun) like this:

Hope this helps
Michael Morris
SCJP
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant that you have to override the run() method, not overload it.
Sorry about that
Michael Morris
SCJP
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!