I have a Super-class A in PackageOne
and a Sub-class B which is in PackageTwo
.
package PackageOne;
public class A {
protected number = 0;
}
Second Class is here
package PackageTwo;
public class B extends A {
public static void main(String args[]) {
A a = new A();
System.out.println(a.number);// Here is the error occurs
}
}
Error is The field Person.name is not visible
;
As I know a protected member can be accessed by a super-class reference, but why the error occurs.