6.4.4
The Members of an Array Type
NAMES
In the example:
interface Colors {
int WHITE = 0, BLACK = 1;
}
interface Separates {
int CYAN = 0, MAGENTA = 1, YELLOW = 2, BLACK = 3;
}
interface ColorsAndSeparates extends Colors, Separates {
int DEFAULT = BLACK;
//
compile time error: ambiguous
}
the members of the interface
ColorsAndSeparates
include those members
inherited from
Colors
and those inherited from
Separates
, namely
WHITE
,
BLACK
(first of two),
CYAN
,
MAGENTA
,
YELLOW
, and
BLACK
(second of two). The
member name
BLACK
is ambiguous in the interface
ColorsAndSeparates
.
6.4.4 The Members of an Array Type
The members of an array type ( 10.7) are all of the following:
Members inherited from its implicit superclass
Object
( 4.3.2, 20.1)
The field
length
, which is a constant (
final
) field of every array; its type is
int
and it contains the number of components of the array
The example:
class Test {
public static void main(String[] args) {
int[] ia = new int[3];
int[] ib = new int[6];
System.out.println(ia.getClass() == ib.getClass());
System.out.println("ia has length=" + ia.length);
}
}
produces the output:
true
ia has length=3
This example uses the method
getClass
inherited from class
Object
and the
field
length
. The result of the comparison of the
Class
objects in the second
println
demonstrates that all arrays whose components are of type
int
are
instances of the same array type, which is
int[]
.
88
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