Name: clC74495 Date: 03/24/98
(1) About the test program TP1 below:
Since "java" as a field of class S is private, it cannot be referenced
from class C. Consequently, "java" of "java.lang.System...." should
be interpreted as a package name, not as a field of class S.
======TP1======
1 class C extends S {
2 void f(){
3 java.lang.System.out.println("foo");
4 }
5 }
6
7 class S {
8 private int java;
9 }
======
% javac C.java
C.java:3: Variable java in class S not accessible from class C.
java.lang.System.out.println("foo");
^
C.java:3: Attempt to reference field lang in a int.
java.lang.System.out.println("foo");
^
2 errors
======
-----------------------------------
(2) About the test program TP2 below:
Java's users cannot know private field names of the API core
library. However, for example, "table" is a private field of
java.util.Hashtable, and when users define "table" as a private
field of a user-defined class, an error message occurs that
should not occur.
======TP2======
1 class A {
2 int table;
3 int table1;
4 class MyHashtable extends java.util.Hashtable {
5 int i = table; // NG
6 int j = table1; // OK
7 }
8 }
======
% javac A.java
A.java:5: Variable table in class java.util.Hashtable not accessible from inner class A. MyHashtable.
int i = table; // NG
^
A.java:5: Incompatible type for Identifier. Can't convert java.util.HashtableEntry[] to int.
int i = table; // NG
^
2 errors
======
===============================================================
Carlos.Lucasius@Canada (Mar 24, 1998):
Verified that the reported errors occur for both test programs
(TP1 and TP2). See also: 4053724
(Review ID: 27060)
======================================================================
- relates to
-
JDK-4240480 name00705.html: JLS6.3 private members should not be inherited from superclasses
- Closed