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 Programmer Certification (SCJP/OCPJP) and the fly likes Thread class constructor 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread class constructor" Watch "Thread class constructor" New topic
Author

Thread class constructor

Peter Swiss
Greenhorn

Joined: Mar 03, 2011
Posts: 23
Hi guys,

This piece of code compiles fine



Class C does not implement Runnable. Still, object of C is passed to the Thread constructor.
Here is the API for Thread class.. http://download.oracle.com/javase/6/docs/api/java/lang/Thread.html

The constructors are no-arg, with a Runnable or with a String. How come this code compiles, when class C is not a Runnable nor a String?
Suhrid Karthik
Ranch Hand

Joined: Aug 31, 2008
Posts: 58

The Thread class itself implements Runnable. Hence, since C extends Thread, C also IS-A Runnable.
Peter Swiss
Greenhorn

Joined: Mar 03, 2011
Posts: 23
Ok, thanks Suhrid!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread class constructor
 
Similar Threads
Thread tricky questions.
starting a thread in a constructor
Adding JScrollPane to JPanel?
For an object to be a target for a Thread, that object must be of type:
parameters for Thread constructor (Q46 from Boone�s exam)