• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic