I noticed strange behaviour of access modifier
package protected_test.pack1;
public class Source {
protected int protectedInt= 1;
}
package protected_test.pack2;
import protected_test.pack1.Source;
public class Child extends Source{
public static void main(String[] args) {
System.out.println(new Child().protectedInt);//line 1
System.out.println(new Source().protectedInt);//line 2
}
}
line 1 compiles good but line 2 writes The field Source.protectedInt is not visible
Before this I didn't know anything about this difference. Can you provide good explanation of visibility with details ?