In Java, what happens when you reference a private class in a Vector from outside the class?
Example:
public class A {
private class B {}
public Vector<B> vector = new Vector<B>();
public A() {
vector.add(new B());
}
}
public class C {
public C() {
A a = new A();
a.vector.get(0); // <- What does this return?
}
}
You can try this code:
The class is A$B, so it knows that B is an inner class of A.
But you cannot access any of the members of B. For example, if you change class A to this:
You still won’t be able to do this:
It will say
the type A.B is not visible.