8.6.4
Constructor Throws
CLASSES
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 creation.
8.6.4 Constructor Throws
The
throws
clause for a constructor is identical in structure and behavior to the
throws
clause for a method ( 8.4.4).
8.6.5 Constructor Body
The first statement of a constructor body may be an explicit invocation of another
constructor of the same class, written as
this
followed by a parenthesized argu
ment list, or an explicit invocation of a constructor of the direct superclass, written
as
super
followed by a parenthesized argument list.
ConstructorBody:
{
ExplicitConstructorInvocation
opt
BlockStatements
opt
}
ExplicitConstructorInvocation:
this (
ArgumentList
opt
) ;
super (
ArgumentList
opt
) ;
It is a compile time error for a constructor to directly or indirectly invoke
itself through a series of one or more explicit constructor invocations involving
this
.
If a constructor body does not begin with an explicit constructor invocation
and the constructor being declared is not part of the primordial class
Object
, then
the constructor body is implicitly assumed by the compiler to begin with a super
class constructor invocation
super();
, an invocation of the constructor of its
direct superclass that takes no arguments.
Except for the possibility of explicit constructor invocations, the body of a
constructor is like the body of a method ( 8.4.5). A
return
statement ( 14.15)
may be used in the body of a constructor if it does not include an expression.
In the example:
class Point {
int x, y;
Point(int x, int y) { this.x = x; this.y = y; }
}
178
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved