File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread" Watch "thread" New topic
Author

thread

Yuki Cho
Ranch Hand

Joined: Apr 18, 2001
Posts: 31
can you please clear this up for me?
For extending thread and implementing runnable, which one implements run and which one overrides run.
thanks,
yuki
sona gold
Ranch Hand

Joined: Feb 14, 2001
Posts: 234
both the way of creating a thread have to override the run method


sona<br />SCJP
kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
when u implement an interface u have to give body to all its methods if the class is not declared an abstract one, so in case of Runnable u have to define run method.while in case of extending Thread if u don't define the run method the thread would run but would not do anything as its default version in the Thread class is empty.hope this clears ur doubt.
Yuki Cho
Ranch Hand

Joined: Apr 18, 2001
Posts: 31
so, when extending a thread, we say override the run() method. And for implementing Runnable, we can either say implement run() method or override the run() method. Or both ways can only be overriding the run() method.
thanks,
Yuki
kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
defining an abstract method is also called overriding of an abstract method. so both ways u can say is a case of overriding.but i wonder why u r going so specific???
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Yuki and Kriti

so, when extending a thread, we say override the run() method. And for implementing Runnable, we can either say implement run() method or override the run() method. Or both ways can only be overriding the run() method.


When you are implementing an interface you neccessarily impliment the methods. The reasons is the methods are
abstract implicitely. Ofcourse, while impliment you may
skip some methods and not impliment them, then in such a situation you need to declare the implimenting class as an abstract class.
Focussing on the current question. Runnable interface has just
one method viz., <code>run()</code>. So , when you are implementing multithreading by implimenting the "Runnable" you
"implement" the run() method. What you are doing in this case is defining it (as it already declared in the interface). On the other hand, in case of extending "Thread" you overide the
run() method as in the Thread class we already have a body
of the run() method which does nothing.
Hope this clears the doubt.
Ravindra Mohan.
Yuki Cho
Ranch Hand

Joined: Apr 18, 2001
Posts: 31
Thanks everybody for replying my question. i got it now. :P
-yuki
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: thread
 
Similar Threads
threads
Java class to run a dedicated thread
interrupt and wait
Doubt in K&B SCJP 5: topic Threads
Q on thread at Jxam