Java Reference
In-Depth Information
It is a compile-time error if the same modifier appears more than once in a constructor de-
claration, or if a constructor declaration has more than one of the access modifiers public ,
protected , and private .
It is a compile-time error if the constructor of an enum type (§ 8.9 ) is declared public or pro-
tected .
If no access modifier is specified for the constructor of a normal class, the constructor has
default access.
If no access modifier is specified for the constructor of an enum type, the constructor is
private .
If two or more (distinct) method modifiers appear in a method declaration, it is cus-
tomary, though not required, that they appear in the order consistent with that shown
above in the production for MethodModifier .
Unlike methods, a constructor cannot be abstract , static , final , native , strictfp , or synchron-
ized :
• A constructor is not inherited, so there is no need to declare it final .
• An abstract constructor could never be implemented.
• A constructor is always invoked with respect to an object, so it makes no
sense for a constructor to be static .
• There is no practical need for a constructor to be synchronized , because it
would lock the object under construction, which is normally not made avail-
able to other threads until all constructors for the object have completed their
work.
• The lack of native constructors is an arbitrary language design choice that
makes it easy for an implementation of the Java Virtual Machine to verify
that superclass constructors are always properly invoked during object cre-
ation.
• The inability to declare a constructor as strictfp (in contrast to a method
8.4.3 ) ) is an intentional language design choice; it effectively ensures that
a constructor is FP-strict if and only if its class is FP-strict (§ 15.4 ) .
8.8.4. Generic Constructors
It is possible for a constructor to be declared generic, independently of whether the class
the constructor is declared in is itself generic.
Search WWH ::




Custom Search