ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Java - Outer & Inner & 객체공유
    개발노하우/Java 2007. 4. 18. 12:59

    class Outer{
     public Outer(){}
     private int x = 100; // private 써보기
     private static int y = 200;
     public void setx(int x)
     {
      this.x = x;
     }
     public void disp(){
      System.out.println("x="+x);
      System.out.println("y="+y);
     }
     class Inner{
      public Inner(){}  
      public void disp_in(){
       System.out.println("x="+x);
     
      }
     }
    }

    public class ex_01 {
     public static void main(String[] arg) {
      // ot
      Outer ot = new Outer();
      ot.setx(200);
      Outer.Inner in = ot.new Inner();
      in.disp_in();
      // ot1
      Outer ot1 = new Outer();
      ot1.setx(300);
      Outer.Inner in1 = ot1.new Inner();
      in1.disp_in();
      Outer.Inner in2 = ot1.new Inner();
      in2.disp_in();
     }
    }

Designed by Tistory.