Quote:
So what i have understood about protected inner classes is that they can be used inside the package they belong to & inside a class inheriting the outer base class.
|
No, they can only be used inside the class that contains it, or any class that extends it [the class that contains the inner]. Protected simply implies that no outside class can actually instance it.
Say, you have a main in your base class, then even in that same package you won't be able to do:
Inner inner = new Inner(); nor new Base.Inner();
Since the Inner class is protected in side the base.
You can however instance it inside any class that extends your Base. So this would work nicely INSIDE the class:
Inner inner = new Inner(); or new baseclass.Inner() if you haven't imported baseclass
And again if you had done this say in your main, it wouldn't work again.