aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes public void run() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "public void run()" Watch "public void run()" New topic
Author

public void run()

Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
When you overide this in your code, I understand that you have to use the exact same method - because it's an abstract menthod from the Runnable interface. You can however, put a modifier in front of the method.
Am I right in saying that these modifiers can be any of the following?:
public
protected
synchronized
Can it be declared final - providing you have code in the run() method?(i.e youv'e instantiated it)
Can you confirm that it is illegal to use static on this overidden method.
Thanks in advance


Rob Petterson
SCJP
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Since it's declared public in the interface, you actually cannot make it have less access, so private, protected, and default (ie, no modifier) are not allowed.
Also, you can't make it static, since it's not legal to override an instance method with a static version of the same signature.
You can, however, mark it as synchronized or final, as these are implementation details. Synchronized just means that only one thread can be invoking this run method at one time; final means that no subclasses can override the method. You could also mark this method as native, since that's also an implementation detail.


Rob
SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: public void run()
 
Similar Threads
Thread constructor
Run-time exception from type-casting
Call Overload Version of Thread's run method
return null;
How to make code execute in its own Thread