title: Creating an array of fields in Java
body: <p>I am trying to implement program that will create an array out of the fields of a certain class
  and then access each field</p>
  
  <p>I have the following class:</p>
  
  <pre><code>public class Example {
  
    public int[] a = {1,2,3};
    public int[] b = {1,1,1};
    public int[] c = {2,2,2};
  }
  </code></pre>
  
  <p>In a different class I want to access all of these fields and place them into the array "testArray"</p>
  
  <pre><code>import java.lang.reflect.Field;
  public class Test { 
  
    Example t = new Example();
    Field[] testArray = t.getClass().getFields();
  
    for (Field elem: testArray) {
     // access the fields
    }
  
  }
  </code></pre>
  
  <p>How can I access the fields this way?</p>
  
  <p>NOTE: for some reasone this gives me an error of <em>Syntax error on token ";", { expected after this token</em></p>