Java Reference
In-Depth Information
then the field x of class Point is no longer hidden within class Test . Within instance
methods in the declaration of class Test , the simple name x now refers to the field de-
clared within class Point . Code in class Test may still refer to that same field as super.x .
The expression sample.x still refers to the field x within type Test , but that field is now
an inherited field, and so refers to the field x declared in class Point . The output from
this variant program is:
2 2
2 2
8.3.1.2. final Fields
A field can be declared final 4.12.4 ) . Both class and instance variables ( static and non- static
fields) may be declared final .
It is a compile-time error if a blank final 4.12.4 ) class variable is not definitely assigned
16.8 ) by a static initializer (§ 8.7 ) of the class in which it is declared.
A blank final instance variable must be definitely assigned (§ 16.9 ) at the end of every con-
structor (§ 8.8 ) of the class in which it is declared; otherwise a compile-time error occurs.
8.3.1.3. transient Fields
Variables may be marked transient to indicate that they are not part of the persistent state of
an object.
Example 8.3.1.3-1. Persistence of transient Fields
If an instance of the class Point :
class Point {
int x, y;
transient float rho, theta;
}
were saved to persistent storage by a system service, then only the fields x and y would
be saved. This specification does not specify details of such services; see the specific-
ation of java.io.Serializable for an example of such a service.
8.3.1.4. volatile Fields
The Java programming language allows threads to access shared variables (§ 17.1 ) . As a
rule, to ensure that shared variables are consistently and reliably updated, a thread should
ensure that it has exclusive use of such variables by obtaining a lock that, conventionally,
enforces mutual exclusion for those shared variables.
Search WWH ::




Custom Search