Because you are trying to access a non-stationary inner class from a static method.
The first solution is to change your inner class Bto static:
public class A{
private static class B {
public B() {
System.out.println("class B");
}
}
public static void main(String[] args){
A a = new A();
B b = new B();
}
}
A staticinner class is accessible from anywhere, but non-static, requires an instance of your container class.
Another solution would be:
A a = new A();
B b = a.new B();
, Java: http://www.javaworld.com/article/2077411/core-java/inner-classes.html