title: Accessing properties of subclasses and superclasses in java with reflection
body: <p>I have a number of classes that derive from the same base type. The base type contains all the members common to the subclasses. When subclass is instantiated, I need to access its members through reflection. I need to access all the members of each subclass, but I need to isolate those members that exist in the base class from those that exists in subclasses. For instance:</p>
  
  <pre><code>public abstract class mainBaseClass{
      public String firstname;
      public String lastname;
  }
  public class subClass extends mainBaseClass{
      public String property1;
      public String property2;
  }
  </code></pre>
  
  <p>I am accessing members as follows:</p>
  
  <pre><code>Field[] fields = objectName.getClass().getFields();
  for(Field f : fields){
      Log.d("FIELD NAME", f.getName());
  }
  </code></pre>
  
  <p>When I use reflection to expose the properties contained in an instance of "subClass" how would I differentiate 'firstname' and 'lastname' from 'property1' and 'property2'?</p>
  
  <p>I'm not sure how to implement this. Can somebody offer a solution or maybe a place to look? Thank you! Vivian</p>