Why there is an error in the commented line, because the protesters of the protected class are available to classes in the same package and subclasses in other packages.
package one; public class One { protected int val; }
If you create the same class in the package one
, then there will be no error in the commented line. For a static
variable in both cases there will be no error.
package two; import one.One; public class Two extends One{ private One o = new One(); //private int val = o.val; }