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
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
posted
0
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
posted
0
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???
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
posted
0
Thanks everybody for replying my question. i got it now. :P -yuki