It's not a secret anymore!
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "public void run()" Watch "public void run()" New topic

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?:
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
Rob Ross

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.

SCJP 1.4
I agree. Here's the link:
subject: public void run()
It's not a secret anymore!