6 Replies Latest reply: Dec 6, 2006 9:54 AM by 800322 RSS

    About private member variable access

    807607
      Why it is possible to access the private variable of another object ,
      within the class of same type ?
      Sine you are directly modifying the private variable ..should this be
      allowed ..
      public class testPrivate
      {
           public static void main(String args[])
           {
                A a = new A();
                a.setX();
                
                     
           }
      }
      
      
      class A
      {
           private int x=100;
           private A t;
           public void setX()
           {
               t = new A();
                t.x = 300;
                t.show();
                this.x=200;
                this.show();
           }
           
           public void show()
           {
                System.out.println(x);
           }
      }