Inner & Outer Class Program in java

Write a program in java to demonstrate the Inner & Outer Class

 
public class Outer 
{
 private int x;
 Outer(int value)
 {
  x=value;
 }
 void test()
 {
  Inner obj1=new Inner();
  obj1.display();
 }
 class Inner
 {
  int y;
  Inner()
  {
   y=10;   
  }
  void display()
  {
   System.out.println("Outer Class x value: "+x);
   System.out.println("Inner Class y value: "+y);
  }
 }
 public static void main(String[] args) 
 {
  Outer obj=new Outer(200);
  obj.test();
 }
}

Output

0 comments:

Post a Comment