This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Extending the Thread class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Extending the Thread class" Watch "Extending the Thread class" New topic
Author

Extending the Thread class

Willie Toma
Ranch Hand

Joined: May 11, 2001
Posts: 78
Is creating a subclass of Thread done like this:

Because java supports single inheritance, Thread can be the only superclass.
There is no need to include a run method because it is not implementing a runnable interface.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
[B]Is creating a subclass of Thread done like this:

[/B]

Yes, that is correct.

Because java supports single inheritance, Thread can be the only superclass.

That is true but if you need to, you can implement Runnable and then extend a different class.

There is no need to include a run method because it is not implementing a runnable interface.

That is also true, but if you dont override run() then your class wont do anything. Check out the API for Thread, it states the run method 'does nothing then returns'. So you'll have to do something or there is no purpose in writing a class that extends Thread or implements Runnable.
hope that helps

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Since Thread already implements the Runnable interface, subclasses automatically inherit the implementation. You would normally override run() because Thread.run() does nothing.


------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform


Junilu - [How to Ask Questions] [How to Answer Questions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Extending the Thread class
 
Similar Threads
A Question for beginners - 2
thread
are these one and the same
getParameter problrm
How is main a thread