View Single Post
  #2   Spotlight this post!  
Unread 03-04-2010, 20:07
spartango spartango is offline
Registered User
FRC #0192 (GRT)
Team Role: Alumni
 
Join Date: Nov 2009
Rookie Year: 2008
Location: Palo Alto, CA
Posts: 43
spartango is an unknown quantity at this point
Re: Threads and classes

If FooThread extends thread, then you can still call foo.bar(), but you have to cast the pointer to the FooThread instance to be not a Thread but a FooThread.

So

Thread t = new FooThread();
//you can now start thread or do whatever
//ie
t.start();

//you cannot, however do this:
t.bar();
//Because not ever thread has bar() method. only FooThreads do.
//but this will work:
((FooThread) t).bar();

//Alternatively, you can create your pointer as a FooThread type as opposed to simply a thread
FooThread t = new FooThread();
//this way you can
t.start();
t.bar();
Reply With Quote