Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

public void run()

 
Rob Petterson
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic