title: Problem in Inheritance in Java
body: <p>I have 5 different tables in a database. I have written an abstract "Converter.java" class that take out data from the database and convert it into a "tree.xml" file.</p>
  
  <p>Tree.xml</p>
  
  <pre><code>&lt;?xml version="1.0" standalone="no"?&gt;
  &lt;tree&gt;
     &lt;declarations&gt;
         &lt;attributeDec1 name="name" type="String"/&gt;
     &lt;/declarations&gt;
  
     &lt;branch&gt;
         &lt;attribute name="name" value="process 1"/&gt;
  
         &lt;leaf&gt;
             &lt;attribute name="name" value="process 2"/&gt;
         &lt;/leaf&gt;
  
         &lt;leaf&gt;
             &lt;attribute name="name" value="process 3"/&gt;
         &lt;/leaf&gt;
     &lt;/branch&gt;
  &lt;/tree&gt;
  </code></pre>
  
  <p>So as you can guess, the structure of the above tree.xml will remain same for all the 5 tables. The only difference is in the value of attribute "value".</p>
  
  <p>To get the value of that "value" attribute, the converter first have to query the database for those values.</p>
  
  <p>So, there should be 5 different queries for 5 different tables. So instead of coding 5 different converters, I have made a singele "Converter.java" that has functions like</p>
  
  <ul>
  <li>openTree()</li>
  <li>closeTree()</li>
  <li>openBranch()</li>
  <li>closeBranc()</li>
  <li>openLeaf()</li>
  <li>closeLeaf()</li>
  <li>addAttribute()</li>
  </ul>
  
  <p>Out of the above methods, I have implemented all the methods except addAttribute() method as it will have implementation depending on the table.</p>
  
  <p>After that, I have coded 5 different converters, each for one table and all of them extends "Converter.java"</p>
  
  <p>I have made a field named as "query" in the Converter.java class. As this field is inherited by all the 5 Converters, I have initialized this field in the constructors of those 5 converters.</p>
  
  <p>Now my question is as follows:</p>
  
  <p>Q. I am not confident that whether I have used inheritance correctly or there should be some changes in the above approach?</p>
  
  <p><b>Edit:</b></p>
  
  <p>Q2. I have one more method in Converter.java class that uses "query" field. As the field is not initialized in the Converter.java class, so whether I copy that method in all the 5 child converters or it is okay to put that method in the parent class (i.e. Converter.java)</p>