Hi, guys
need your help!
question:
It is impossible to have an instance of a non-static inner class before any instance of the outer class have been created.
It's in Rules Round-up mock. The answer is True.
But imagine a scenario that a local inner class is in a static method, then its instance can be used without any instance of the outer class, like the code follows. Is there anything wrong?
class TestInner{
static void methodA() {
class inner{
inner(){ System.out.println("inner init"); }
};
inner i=new inner();
System.out.println("methodA");
}
}
class Test{
public static void main(
String[] args){
TestInner.methodA();
}
}