aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Runnable to Thread Casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Runnable to Thread Casting" Watch "Runnable to Thread Casting" New topic
Author

Runnable to Thread Casting

Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 180


Why the casting gives ClassCastException? Thread class provides the implementation for Runnable interface. Then why cannot we cast???
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
This is because r1 is an implementer of the Runnable Interface. Thread class also is an implementer of Runnable. But there is no relation between r1(anonymous sub-class referenced by r1) and the Thread class.
Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 180
ohhhhhh. Yes r1 is just an implementor reference not Runnable reference. So we cannot . Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runnable to Thread Casting
 
Similar Threads
threads and uncaught exceptions
Exercise 13.6 in - A Programmer's Guide to Java SCJP Certification - 3rd Ed
Threads blocking on static method.... or do they?
Synchronization lock
Thread Synchronization