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

Threads

Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
OK, I just need to get a few loose ends tied up here.
1. public void run() has to appear like this in code which implements Runnable.It's signature must stay the same and with no args added to the param. Is this correct?
2. Do the same rules apply to code that extends Thread as well, or is it OK if we even don't include this method in the code - will it give compile time error?
3. I know that Runnable is an abstract class and that the run() method is abstract, and can therefore understand that it must appear in code that implements Runnable. If you didn't incl run(), would that mean that you'd have to declare the class that implements Runnable as abstract?
4. Am I right in saying that Thread class already inherits from Runnable? If that's the case what implications does that have on Thread class?
The rest of the stuff on Threads I'm ok with. It's just some of these fundamental issues Iv'e got to get clear in my head.


Rob Petterson
SCJP
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
1. public void run() has to appear like this in code which implements Runnable.It's signature must stay the same and with no args added to the param. Is this correct?
correct
2. Do the same rules apply to code that extends Thread as well, or is it OK if we even don't include this method in the code - will it give compile time error?
Thread implements Runnable and provides an empty body for the run() method. If you don't override run() when subclassing Thread,your thread won't do anything.
There won't be any compilation error if you don't override the method run() since it is provided by the Thread class.
3. I know that Runnable is an abstract class and that the run() method is abstract, and can therefore understand that it must appear in code that implements Runnable. If you didn't incl run(), would that mean that you'd have to declare the class that implements Runnable as abstract?
Runnable is not an abstract class but an interface, both are different and that difference is very important.
If your class implements the Runnable interface and doesn't provide an implementation for the run() method then you have to declare your class abstract.
4. Am I right in saying that Thread class already inherits from Runnable? If that's the case what implications does that have on Thread class?
Again, the Thread class implements Runnable, this means that the Thread class provides an empty implementation for the run() method.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
Thanks Valentin for the clarrification
Gautam Sewani
Ranch Hand

Joined: Apr 19, 2002
Posts: 93

1. public void run() has to appear like this in code which implements Runnable.It's signature must stay the same and with no args added to the param. Is this correct?

Thats correct.

2. Do the same rules apply to code that extends Thread as well, or is it OK if we even don't include this method in the code - will it give compile time error?

No,the same rules dont apply for the code that extens Thread,as thread as already a blank run method defined,and so the code which does not define a run method explicitly will not give compile time errors.

3. I know that Runnable is an abstract class and that the run() method is abstract, and can therefore understand that it must appear in code that implements Runnable. If you didn't incl run(), would that mean that you'd have to declare the class that implements Runnable as abstract?

First of all,runnable is an interface and not an abstract class.Rest everything is correct about your statement.

4. Am I right in saying that Thread class already inherits from Runnable? If that's the case what implications does that have on Thread class?

The thread class implements runnable.It does not have any particular implications,except that a thread class also can be used as another thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads