Public versus Private 

class MyClass {

     public int x;
     private int y;

     public void method1() {
        
          x = 5;
          y = 7;
          method2();    
       }

     private void method2() {
 
         x = 8;
         y = 9;  

     }
}

Somewhere in another class ...

     public static void main(String[] args)

        {
             MyClass fred;

             fred = new MyClass();

             fred.x = 17;  // this is OK
             fred.y = 15;  // this generates an error
             fred.method1();  // this is OK
             fred.method2();  // this generates an error
        }