• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why should we pass the object of the class implemented from runnable to thread class constructor?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi my doubt is in java.My doubt is on creating thread by implementing runnable interface.
Please see the below programme.
In below programme I have implemented the class countdowneven from Runnable.
In main method I am passing the object of countdown even to constructor of thread class.
Why should we pass the object of countdowneven to constructor of thread class?
What operations will be performed by Thread class constructor on object of countdowneven?
-------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------
Output:
10
8
6
4
2

 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you implement the Runnable interface, the class becomes a Runnable object. There is a constructor of the Thread class which accepts a Runnable parameter. When the start method is called on that thread, it will cause the run() method in the Runnable class to execute.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic