permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous class 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 "Anonymous class" Watch "Anonymous class" New topic
Author

Anonymous class

Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Hi, This is from ExamLab. Please advice why I am getting this error at Line 9.
swaraj gupta
Ranch Hand

Joined: Oct 22, 2010
Posts: 181

Saibabaa Pragada wrote:Hi, This is from ExamLab. Please advice why I am getting this error at Line 9.


rb is Runnable(Supertype) type reference-variable and is referring to an instance of its anonymous subclass(Subtype), so using that reference it is not possible to invoke a method that does not exist in Runnable<interface>.

Note: When super class reference-variable is referring subclass instance then through that reference only those methods can be invoked that exists in both superclass and the subclass.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Can you please check the API for Runnable to see if it has start() method defined for it? You always use a Thread instance to start the thread.


Mohamed Sanaulla | My Blog
Imad Aydarooos
Ranch Hand

Joined: Nov 02, 2010
Posts: 87
You have to pass the Runnable type object to a Thread object, after that you have to invoke start() on the Thread object


love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
Mark Guo
Ranch Hand

Joined: Nov 17, 2010
Posts: 58


This is the correct way to invoke start();

Regards!


 
jQuery in Action, 2nd edition
 
subject: Anonymous class
 
Similar Threads
Given: ...
Threads
Thread question