Why can't i access a protected inner class' constructor in a subclass?
Assume,
//Inteface1.java
package packagea;
public interface Interface1{
void f();
}
//Class1.java
package packagea;
public class Class1{
protected class InnerClass implements Interface1{
public void f(){
System.out.println("Class1.InnerClass.f()");
}
}
}
//SubClass.java
package packageb;
import packagea.*;
public class SubClass extends Class1{
public Interface1 getInterface1(){
return new InnerClass(); //Error thrown here in JDK
}
public static void main(
String [] args){
new SubClass().getInterface1().f();
}
}
Error Message in JDK1.5.0.12: "InnerClass() has protected access in packagea.Class1.InnerClass"
I dont understand why this error is thrown? As a subclass, i have the rights to access protected members of a
superclass, innit? Or are the rules different for constructors of inner classes?
As expected, all the files compile and the app runs if i make a public default constructor for InnerClass.