title: Inheritance in variables, access from parent to child variable value
body: <p>I am trying to make a super class to access DataModels in a SQLite database (in Android). I want to change a variable value in the child but use it in the parent.</p>
  
  <p>This is the portion of code from the superclass:</p>
  
  <pre><code>public class DataModel&lt;T&gt; {
      public static String table = null;
  
      static String getTableName(){
          String tableName = null;
          Class&lt;?&gt; enclosingClass = DataModel.class;
          tableName = enclosingClass.getSimpleName().toLowerCase() + "s";
          if(table != null){
              tableName = DataModel.table;
          }
          return tableName;
      }
  }
  </code></pre>
  
  <p>The child class:</p>
  
  <pre><code>public class User extends DataModel {
      static {
          String table = "test_users_table";
      }
  }
  </code></pre>
  
  <p>I have some issues with the table variable: It comes null. Adding more strange behaviour the process enters the if statement even of being null the var.</p>
  
  <p>I supose I am doing it bad and I am missunderstanding some concept. What is the right aproach?</p>
  
  <p>Beside this, how can I get child class name? I always take datamodels as a result to <code>enclosingClass.getSimpleName().toLowerCase() + "s"</code>.</p>
  
  <p><strong>EDIT:</strong> The class DataModel will be the base class for all my database models. What I try is to make a class with the ability to encapsulate SQL queries, I mean, when I need to load a concrete model like a user, I call the static method <code>User.find(id)</code>, which connects to the SQLite and returns an instantiated User object with the data loaded. I could do this directly on the USer class, but I try to do this in the DataModel in order to do <code>Product.find(x)</code>, <code>Post.find(x)</code>. Later I could add methods like save to encapsulate INSERTS and UPDATES.</p>
  
  <p>At last I would have a base class which would do all the job for me, and the db methods would be written once.</p>
  
  <p>In this concrete code portion I am trying to pass to the DataModel the table name for this example (users).</p>