This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 4458
    
    6

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]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Extending the Thread class