title: Is it possible to invoke private attributes or methods via reflection
body: <p>I was trying to fetch the value of an static private attribute via reflection, but it fails with an error.</p>
  
  <pre><code>Class class = home.Student.class;
  Field field = studentClass.getDeclaredField("nstance");
  Object obj = field.get(null);
  </code></pre>
  
  <p>The exception I get is:</p>
  
  <pre><code>java.lang.IllegalAccessException: Class com.test.ReflectionTest can not access a member of class home.Student with modifiers "private static".
  </code></pre>
  
  <p>Moreover, there is a private I need to invoke, with the following code.</p>
  
  <pre><code>Method method = studentClass.getMethod("addMarks");
  method.invoke(studentClass.newInstance(), 1);
  </code></pre>
  
  <p>but the problem is the Student class is a singleton class, and constructor in private, and cannot be accessed.</p>