• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads & Inheritence  RSS feed

 
Suneel Setlur
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are Threads and Inheritence related ? Do threads help in multiple inheritence ?

------------------
Suneel
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread is like any other Java class which can be subclassed. If you want to add threading feature to your class, you can exted the Thread class and override the run method.
Since Java doesnot allow multiple inheritance you may be in trouble if your class already extends another class and you need to add threading functionality. In such a case you can implement the Runnable interface instead of extending the Thread class. Since interfaces provide an alternative( and safe ) way of implementing multiple inheritance, the java language designers wrote an interface-implementation of Thread. Infact the Thread class itself implements the Runnable interface.
Does that answer your question??
Ajith
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!