File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread

 
Phungsuk Wangdu
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why does this class compile since there is no run method defined
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rename the start method() to run()

hth
 
Raju Champaklal
Ranch Hand
Posts: 521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Threads is class that implements the Runnable interface....and since Thread isnt an abstract class run method must be implemented in it....so you can call run on Thread class but it does nothing
 
Phungsuk Wangdu
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

no no i got it but its not what you said
actually we are extending thread class so its default run method is automatically inherited which does nothing ....
found this just now on a website
btw thanks
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.Thread class implements Runnable interface and Runnable interface is having abstract run() method which has to be implement in every class which extends to Thread or implement Runnable.
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh forget my last post its not true , thread class it self implements run() method you don't need to implement run() in your class which extends to thread class.

but in case of runnable if you implement runnable interface you have to implement run() method.
 
Ben Power
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minhaj kaimkhani wrote:...thread class it self implements run() method....

but in case of runnable if you implement runnable interface you have to implement run() method.


Yes. Thread does implement Runnable and it properly overrides the run() method, fulfilling the requirement to override run(). So when you extend Thread you inherit the perfectly good run() method in the Thread class. Note that while it fulfills the technical requirement to fulfill the run() method, it does not fulfill the practical need to create a usable run() method in your subclass. It compiles, but it's not useful.

On the other hand, if you create a class that implements Runnable, you need to override the run() method. Just in this case, you were technically inheriting Thread's run() method.

Ben
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic