title: Why I cannot declare objects for inner classes in the way mentioned in code?
body: <p>This code is working properly.However, when i try to change the position of inner class object ,the code isn't working</p>
  
  <pre><code>class Outer {
      int outer_x = 100;
  
      void test() {
          for(int i=0; i&lt;10; i++) {
              class Inner {
                  void display() {
                      System.out.println("display: outer_x = " + outer_x);
                  }
              }
  
              //when i create oject for Inner class here code is working
              Inner inner = new Inner();
              inner.display();
          }
      }
  }
  
  class InnerClassDemo {
      public static void main(String args[]) {
          Outer outer = new Outer();
          outer.test();
      }
  }
  </code></pre>
  
  <p>But when i place Inner class object as in the code below ,code is not working. The IDE was not able to find the inner class while declaring the inner class below its instance</p>
  
  <pre><code>class Outer {
      int outer_x = 100;
  
      void test() {
          for(int i=0; i&lt;10; i++) {
              //now i created object for inner class here
              Inner inner = new Inner();
              inner.display();
  
              class Inner {
                  void display() {
                      System.out.println("display: outer_x = " + outer_x);
                  }
              }
          }
      }
  }
  
  class InnerClassDemo {
      public static void main(String args[]) {
          Outer outer = new Outer();
          outer.test();
      }
  }
  </code></pre>