Java Reference
In-Depth Information
Point(int x, int y) { this.x = x; this.y = y; }
}
Constructors are invoked by class instance creation expressions (§ 15.9 ) , by the conversions
and concatenations caused by the string concatenation operator + 15.18.1 ), and by expli-
cit constructor invocations from other constructors (§ 8.8.7 ) .
Constructors are never invoked by method invocation expressions (§ 15.12 ) .
Access to constructors is governed by access modifiers (§ 6.6 ) .
This is useful, for example, in preventing instantiation by declaring an inaccessible
constructor (§ 8.8.10 ) .
8.8.1. Formal Parameters and Type Parameters
The formal parameters and type parameters of a constructor are identical in syntax and se-
mantics to those of a method (§ 8.4.1 ) .
8.8.2. Constructor Signature
It is a compile-time error to declare two constructors with override-equivalent signatures
8.4.2 ) in a class.
It is a compile-time error to declare two constructors whose signatures have the same eras-
ure (§ 4.6 ) in a class.
8.8.3. Constructor Modifiers
ConstructorModifiers:
ConstructorModifier
ConstructorModifiers ConstructorModifier
ConstructorModifier: one of
Annotation public protected private
If an annotation a 9.7 ) on a constructor corresponds to an annotation type T 9.6 ) , and
T has a (meta-)annotation m that corresponds to java.lang.annotation.Target , then m must have
an element whose value is java.lang.annotation.ElementType.CONSTRUCTOR , or a compile-time
error occurs.
The access modifiers public , protected , and private are discussed in § 6.6 .
Search WWH ::




Custom Search