title: Inner Class object inside outer class
body: <pre><code>class Outer
  {
      int outer_x = 100;
      
      void test()
      {
          Inner inner = new Inner();
          System.out.println(inner.i);
          inner.display();
      }
      
      class Inner
      {
          int i = 12;
          void display()
          {
              System.out.println(&quot;outer_x : &quot; + outer_x);
          }
      }
      
      
      Inner inneri = new Inner();
      {
      inneri.display() ;
      System.out.println(inneri.i);        // This runs with no compile error
      }
      
      //System.out.println(inneri.i);      // This gives compile error
      }
  class NestedClass
  {   
      public static void main(String args[])
      {
          Outer outer = new Outer();
          outer.test();
      }
  }
  
  </code></pre>
  <p>I have made an Inner class object inneri, in class Outer. If I run it inside a block, it runs fine, but it shows compile error outside the block. Why? Also why it is running inside the block without any Outer object?</p>