java - Access control -- protected members from outside the package -
i've got class p4 in default package (i know using default package bad practice, merely "for example" now):
import temp.p2; public class p4 extends p2 { public void somemethod() { p2 p2 = new p2(); // p2.p2default(); // error expected p2.p2public(); p2.p2protected(); // error not expected } } and class p2 in package temp
package temp; public class p2 { protected void p2protected() { ... } public void p2public() { ... } void p2default() { ... } } from access control mechanism, i'd expect p4-- having extended p2, should able see protected member of super class outside package once imported namespace of package.
what missing?
tia.
you defined p2 p2 = new p2(); of type p2 , not p4. if p2 of type p4 have access since subclass of p2.
Comments
Post a Comment