• Post Reply Bookmark Topic Watch Topic
  • New Topic

why java provided Thread and Runnable both  RSS feed

 
vikram sinhg
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why java provided Thread and Runnable both?
please answer this question.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think they thought they were making things more convenient for programmers, by offering more than one way to do things. I think in reality they would have been better off making Thread not implement Runnable, and make Thread final, so that you always implement Runnable to define what you want a thread to do, and then create a Thread to actually do it. That would save a lot of unnecessary confusion among new programmers.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because Java only allows single inheritance, a class definition cannot both extend another class like JApplet or JFrame and extend Thread. A class definition can implement the Runnable interface, and then a Thread can be created using that class definition.
 
vikram sinhg
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it is still not perfect answer.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perfect answer?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gee, that's too bad.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vikram sinhg:
No, it is still not perfect answer.


Either that was an insult or it's the product of a language barrier. Please consider rewording that sentence. What about the answer is insufficient?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why java provided Thread and Runnable both?


Youthful indescretion? Temporary insanity? Too many late nights? Something like that. Not necessary, quite possibly A Bad Thing.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I think it's a good thing that Thread and Runnable are separate. The bad part is that they also made Thread implement Runnable, and people now have the rather pointless choice of whether to extend Thread or implement Runnable directly. The latter is more flexible, so the former is just an annoying and unnecessary cause for confusion among beginners. In my opinion, of course...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!