Posted by : Unknown Sunday, 5 July 2015


class Outer 
{
     int outer_x = 100;
     void test() 
     {
          Inner inner = new Inner();
          inner.display();
     }
     
     // this is an inner class
     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();
      }
}

Output:

Display: outer_x = 100

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Translate

Popular Post

Total Pageviews

- Copyright © Learning Java Program - Powered by Blogger -