title: private variable constraints java
body: <p>Just for the sake of example I am putting in String as member variable. But there is complex structure originally.</p>
  
  <pre><code>public class ClassA {
  
      private final String test ;
  
      public ClassA(String str) {
          test = str;
      }
  
      @Override public int hashCode() {
          return test.hashCode();
      }
  
      @Override public boolean equals(Object obj) {
          return obj instanceof ClassA &amp;&amp; test.equals(((ClassA)obj).test);
      }
  
  }
  
  
  public class ClassB {
  
      public static void main(String args[])
      {
          ClassA obj1 = new ClassA("abc");
          ClassA obj2 = new ClassA("def");
          obj1.equals(obj2);
          obj2.test;//not valid
      }
  }
  </code></pre>
  
  <p>From what I know access to the private variable <code>test</code> of <code>obj1</code> is there only within the methods of ClassA and these methods should be called from the context of <code>obj1</code>. </p>
  
  <p>When I called <code>obj1.equals(obj2)</code> test variable of obj2 is accessible from the obj1's context. </p>
  
  <p>So can we access the private variables of any object of type ClassA from within ClassA methods.  </p>