This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor Modifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor Modifiers" Watch "Constructor Modifiers" New topic
Author

Constructor Modifiers

Jimmy Blakely
Ranch Hand

Joined: Jul 10, 2001
Posts: 57
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

Joined: Jun 13, 2000
Posts: 3340
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.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Jimmy Blakely
Ranch Hand

Joined: Jul 10, 2001
Posts: 57
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor Modifiers
 
Similar Threads
What does Mr Khalid mean here?
scope of local vars.../even in main()/access modifiers
doubt in constructor
Constructors & Exceptions
Default constructor