Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extending the Thread class

 
Willie Toma
Ranch Hand
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
 
Junilu Lacar
Bartender
Pie
Posts: 6531
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic