This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor Modifiers

 
Jimmy Blakely
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aside from accessibility modifiers, do constructors accept any other types of modifiers?

I'm currently testing the hypothesis that constructors can only be preceded by accessibility modifiers (public, private, protected, default). Is this true?
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct!
If you put a return type, java considers it to be a method and it will not create that constructor. Modifiers such a synchronized, native ext. wll throw a compile time exception.
 
Jimmy Blakely
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind.
I just finished testing it out.
Constructors cannot accept static, final, abstract, synchronized, or native as modifiers.
Naturally, the same is true for transient and volatile since they are only used to modify variables and not methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic