Assume I have a base class with a package accessible member:
package testcase;
public class B
{
int b;
}
And it has a subclass:
package testcase.sub;
import testcase.B;
public class C
extends B
{
int c;
}
Now I need to access the member field from within the same package that defined the field:
package testcase;
import testcase.sub.C;
public class A
{
void testcase( C c )
{
c.c = 0; // HINT
( (B) c ).b = 1; // FIRST
c.b = 2; // SECOND
}
}
EDIT: I absolutely understand that A
cannot access c.c
and why the line marked HINT does not compile: C.c
is only visible to code in the same package and while C.c
is in package testcase.sub
A
is in testcase
.
However A
and B.b
are both in package testcase
so why does the first assignment compile, while the second does not?