Alina, what you said is correct. I tested it and it works fine. If we have an outer class MyOuter with inner class MyInner in some package
Test then you can refer to Inner class with their simple name 'MyInner' if there is an import statement 'import Test.MyOuter.MyInner'. But this works will work only with public accessiblity. so class MyOuter, MyInner should have public accessibility and also their constructors. But what if I give MyInner class a protected access and try using it in an extended class.
package outer; public class MyOuter
{
int i;
protected class MyInner
{
final int j = 5;
protected MyInner()
{
System.out.println(j);
}
}
}
package test; import outer.MyOuter;
class OuterInnerTest
extends MyOuter {
public static void main(
String args[])
{
OuterInnerTest t = new OuterInnerTest();
t.test();
}
void test()
{
MyInner in = this.new MyInner();
}
}
This gives me compilation error:
MyInner() has protected access in outer.MyOuter.MyInner
OuterInnerTest class is extending MyOuter class then this should be allowed. right?