6.4.2
The Members of a Class Type
NAMES
package vector;
public class Vector { Object[] vec; }
that has as a member a
public
class named
Vector
, even though the standard
package
java.util
also declares a class named
Vector
. These two class types
are different, reflected by the fact that they have different fully qualified names
( 6.7). The fully qualified name of this example
Vector
is
vector.Vector
,
whereas
java.util.Vector
is the fully qualified name of the standard
Vector
class. Because the package
vector
contains a class named
Vector
, it cannot also
have a subpackage named
Vector
.
6.4.2 The Members of a Class Type
The members of a class type ( 8.2) are fields and methods. The members of a
class type are all of the following:
Members inherited from its direct superclass ( 8.1.3), if it has one (the class
Object
has no direct superclass)
Members inherited from any direct superinterfaces ( 8.1.4)
Members declared in the body of the class ( 8.1.5)
Constructors ( 8.6) are not members.
There is no restriction against a field and a method of a class type having the
same simple name.
A class may have two or more fields with the same simple name if they are
declared in different interfaces and inherited. An attempt to refer to any of the
fields by its simple name results in a compile time error ( 6.5.6.2, 8.2).
In the example:
interface Colors {
int WHITE = 0, BLACK = 1;
}
interface Separates {
int CYAN = 0, MAGENTA = 1, YELLOW = 2, BLACK = 3;
}
class Test implements Colors, Separates {
public static void main(String[] args) {
System.out.println(BLACK); //
compile time error: ambiguous
}
}
the name
BLACK
in the method
main
is ambiguous, because class
Test
has two
members named
BLACK
, one inherited from
Colors
and one from
Separates
.
86
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