aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Solve this thread question!! confused!! 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 "Solve this thread question!! confused!!" Watch "Solve this thread question!! confused!!" New topic
Author

Solve this thread question!! confused!!

himanshu kesarwani
Ranch Hand

Joined: Aug 27, 2008
Posts: 84
this questuin is from examulator....
i am not geting why its giving compile error telling run() must be overidden....
is is compulsory to override run() when implementing runnable.
is the same case is with extending Thread also.

As what i think is that as no thread object is created there should not be any problem and start() should be run like normal method!!









SCJP 5
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
Please go through the thread basics again,

If you implement Runnable or extend Thread class, run() is the method you need to override and not start(). Start() is used to call start the thread, which in turn calls run() method


<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
Cristian Senchiu
Ranch Hand

Joined: Feb 08, 2009
Posts: 40
himanshu kesarwani wrote:...
i am not geting why its giving compile error telling run() must be overidden....
is is compulsory to override run() when implementing runnable.
is the same case is with extending Thread also.
As what i think is that as no thread object is created there should not be any problem and start() should be run like normal method!!

Himanshu,
your class implements the Runnable interface.
Runnable interface declares a method run(), so you have to give implementation for it in your class, whether you use it or not.
And no, it is not the same as extending Thread class , where you can choose if you override or not the run() method.
Chaitanya Jadhav
Ranch Hand

Joined: Mar 13, 2009
Posts: 41
* If you implements Runnable you MUST override :- public void run(){}

* If you extends Thread class you not need to override run() method.

see example:

class Test implements Runnable
{
public void run(){
System.out.println(&quot;In run Method &quot;);
}
public void start(){
System.out.println(&quot;In start Method &quot;);
}
public static void main(String[] args)
{
Test obj=new Test();
obj.start(); // start method call like other normal method
Thread t=new Thread(obj); //
t.start();// Thread.start() method automatically call run() method


}
}


SCJP 1.5 80%
himanshu kesarwani
Ranch Hand

Joined: Aug 27, 2008
Posts: 84
ya this is what i wanted i was olly confused about the extending thread as in k&b it was there......telling about it!!
so i thought that the case must be same for Runnable even.......
thanks guys...
i am solving examulator exam,and getting average 80%....
can you guys tell me more better and FREE mock exams......!!
i heard whizlabs and devaks mock exams are very good but i didnt get them in free........how can i get them in free.... !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Solve this thread question!! confused!!