• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Mixing method modifiers and return type in a method declaration

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a mock exam question I thought that this was a good declaration of a method:

public void synchronized amethod3(){ }

I saw I was wrong when I review the answer. But the exact reason is not 100% clear to me. Doing some testing I think you can mix the order of all modifiers (access modiefiers, abstract, synchronized) but the return type of the method must be placed directly before the methods name. Is that correct?


Here is my test program I tried to compile:

class test {
public synchronized void amethod1(){ }
synchronized public void amethod2(){ }
public void synchronized amethod3(){ } // does not compile
void public amethod4(){} // does not compile
void public abstract amethod5(); // does not compile
}
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're right. see JLS
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic