Java Reference
In-Depth Information
A resource of a try -with-resources statement (§ 14.20.3 ) and an exception parameter of a
multi- catch clause (§ 14.20 ) are implicitly declared final .
An exception parameter of a uni- catch clause (§ 14.20 ) may be effectively final instead of
being explicitly declared final . Such a parameter is never implicitly declared final .
4.12.5. Initial Values of Variables
Every variable in a program must have a value before its value is used:
• Each class variable, instance variable, or array component is initialized with a de-
fault value when it is created (§ 15.9 , § 15.10 ) :
♦ For type byte , the default value is zero, that is, the value of (byte)0 .
♦ For type short , the default value is zero, that is, the value of (short)0 .
♦ For type int , the default value is zero, that is, 0 .
♦ For type long , the default value is zero, that is, 0L .
♦ For type float , the default value is positive zero, that is, 0.0f .
♦ For type double , the default value is positive zero, that is, 0.0d .
♦ For type char , the default value is the null character, that is, '\u0000' .
♦ For type boolean , the default value is false .
♦ For all reference types (§ 4.3 ), the default value is null .
• Each method parameter (§ 8.4.1 ) is initialized to the corresponding argument value
provided by the invoker of the method (§ 15.12 ).
• Each constructor parameter (§ 8.8.1 ) is initialized to the corresponding argument
value provided by a class instance creation expression (§ 15.9 ) or explicit con-
structor invocation (§ 8.8.7 ) .
• An exception parameter (§ 14.20 ) is initialized to the thrown object representing
the exception (§ 11.3 , § 14.18 ) .
• A local variable (§ 14.4 , § 14.14 ) must be explicitly given a value before it is used,
by either initialization (§ 14.4 ) or assignment (§ 15.26 ) , in a way that can be verified
using the rules for definite assignment (§16).
Example 4.12.5-1. Initial Values of Variables
Click here to view code image
class Point {
static int npoints;
Search WWH ::




Custom Search