Suppose I change a public ivar in a superclass to private. The
subclass access to the ivar at runtime will still be allowed. The
AccessCheck() routine is only implemented in the compiler.
For instance, consider the following files
bug133a.java --------------------
package bug133package;
public class bug133a {
public int v = 3;
}
bug133.java --------------------
class bug133 extends bug133package.bug133a {
public int readV(){
return v;
}
public static void main( String x[] )
{
bug133 b = new bug133();
System.out.println( b.readV() );
}
}
-------------------------------
Compile them and run.
ganymede% javac -d . bug133a.java
ganymede% javac bug133.java
ganymede% java bug133
3
So far, so good. Now I change bug133package.bug133a.v to private,
recompile that file and re-run.
ganymede% javac -d . bug133a.java
ganymede% java bug133
3
The subclass still accesses the now-private superclass member.
Of course, recompiling the subclass gets an error, AS IT SHOULD.
ganymede% javac bug133.java
bug133.java:3: Variable v in class bug133package.bug133a not accessible from class bug133.
return v;
^
1 error
subclass access to the ivar at runtime will still be allowed. The
AccessCheck() routine is only implemented in the compiler.
For instance, consider the following files
bug133a.java --------------------
package bug133package;
public class bug133a {
public int v = 3;
}
bug133.java --------------------
class bug133 extends bug133package.bug133a {
public int readV(){
return v;
}
public static void main( String x[] )
{
bug133 b = new bug133();
System.out.println( b.readV() );
}
}
-------------------------------
Compile them and run.
ganymede% javac -d . bug133a.java
ganymede% javac bug133.java
ganymede% java bug133
3
So far, so good. Now I change bug133package.bug133a.v to private,
recompile that file and re-run.
ganymede% javac -d . bug133a.java
ganymede% java bug133
3
The subclass still accesses the now-private superclass member.
Of course, recompiling the subclass gets an error, AS IT SHOULD.
ganymede% javac bug133.java
bug133.java:3: Variable v in class bug133package.bug133a not accessible from class bug133.
return v;
^
1 error