I have a class called A in package1 and another class called C in package2. Class C extends class A.
A has an instance variable which is declared like this:
<
Since C
is inheriting A
, C
can directly use the protected
variable of A
like below
public class C extends A{
public void go(){
System.out.println(protectedInt);
}
}
As per your code, you are creating an instance of A
and accessing protected
variable through that instance, which violates java's rule - A protected variable is not visible outside the package