title: Access members of a non public class from outside the package using java reflection
body: <p>There is a non-public class A in package1.I want to access the members of this class from another class B in package2. I have made an instance of class A using the constructor.how would I access the fields and methods in class A?</p>
  
  <pre><code>package package1;
  class A {
      Integer i;
  }
  
  package package2;
  class B {
      public void accessClassA() {
  
          Class aClass = Class.forName("package1.A");
          Constructor&lt;?&gt; con = aClass.getDeclaredConstructor();
          con.setAccessible(true);
          //code to access fields of class A
  
      }
  }
  </code></pre>