I have an abstract class, relation in package database.relation and a subclass of it, Join, in package database.operations. relation has a protected member named mStructure.
In Join:
public Join(final Relation relLeft, final Relation relRight) {
super();
mRelLeft = relLeft;
mRelRight = relRight;
mStructure = new LinkedList<Header>();
this.copyStructure(mRelLeft.mStructure);
for (final Header header :mRelRight.mStructure) {
if (!mStructure.contains(header)) {
mStructure.add(header);
}
}
}
On lines
this.copyStructure(mRelLeft.mStructure);
and
for (final Header header : mRelRight.mStructure) {
I get the following error:
The field Relation.mStructure is not visible
If I put both classes in the same package, this works perfectly. Can anyone explain this issue?
It works, but only you the children tries to access it own variable, not variable of other instance ( even if it belongs to the same inheritance tree ).
See this sample code to understand it better:
If we try to compile using the
withParent.parentVariablewe’ve got:It is accessible, but only to its own variable.