when we compile the class Run2 we get compilation errors as
com\jspiders\app2\Run2.java:10: error: i has protected access in D
d1.i = 456;
com\jspiders\app2\Run2.java:11: error: print() has protected access in D
However if we change the class Run2 as follows it compiles.
Can you please explain why D d1 = new Run2() fails to compile and Run2 d1 = new Run2() compiles successfully?
I'm actually surprised the second one compiles. To be able to access a protected member of a superclass that's not in the same package, you're supposed to have to do it as this.member or super.member. I don't think you're allowed to do arbitrary_subclass_reference.member.
But maybe I'm wrong. Maybe it's just that you have to do it through a subclass reference, not a superclass reference.