wood burning stoves 2.0*
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
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: 5288
    
  10

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extending the Thread class