Does ParentClass.NestedClass nc= new NestedClass(); implicitly instantiate parent class instance?

Viewed 42

I have a code from textbook:

public class Question_3_4 {
  public static class Inner {
    private void doIt() {
      System.out.println("doIt()");
    }
  }
  public static void main(String[] args) {
    Question_3_4.Inner i = new Inner();
    i.doIt();
  }
}

Well, Inner class is static, so I assume the above code implicitly instantiates Question_3_4's instance ?

Question_3_4.Inner i = new Question_3_4.Inner();

produces the same result as above code.

So I assume

  Question_3_4.Inner i = new Question_3_4.Inner();   

and

  Question_3_4.Inner i = new Inner();

are the same thing.

If my assumption is wrong what I am missing here?

3 Answers
Related