Let's say I have a class like this:
public class OuterClass {
//...
private class InnerClass {
private int x; // This variable makes sense
public int y; // Is there any use for this?
}
}
In the code above, since the inner class is private, only the outer class has access to all its variables, even the private ones. The inner class itself is not visible to any other class but the enclosing outer class.
So even though variable y
above is public, it cannot be accessed by any other class other than the outer class.
It would seem all access modifiers in the private inner class are by default private, aren't they?
So given that, is there any reason to declare access modifiers at all for any of the members of the inner class?