Could you tell me 1) why you can make the constructor public for a class with a visible package? For instance:
class TestModifiers {
public TestModifiers() {
}
}
This class cannot be instantiated everywhere, but in the same package. So is this not enough to use the visible package modifier for the constructor? This is true for any method (public) in such a class (visible package)
2) let's say in the inner class I created two private variables . Why can I see them from the outer class? Isn't that weird? For instance:
class A {
A(){}
class B {
private int b1;
private int b2;
}
public static void main(String[] args) {
new B().b1 = 1;
new B().b2 = 2;
}
}
source
share