I have 3 class A, B, C :
package com.training.protectedclass.A; public class A { protected int value; } package com.training.protectedclass.B; import com.training.protectedclass.A.A; public class B extends A { public void test() { this.value = 10; A a = new A(); a.value = 12; //Error => The field A.value is not visible } } package com.training.protectedclass.C; import com.training.protectedclass.B.B; import com.training.protectedclass.A.A; public class C extends A { public void test() { B b = new B(); b.value = 45; //Error => The field A.value is not visible } } When the inherited class exists in different package than the base class, it can't access the protected member of base class. But when all the three class exist in the same package the above errors disappear and the code is compiled without errors.
Can anyone explain me the cause of each error launched in my code above?
Thanks :)