title: Java - Can we declare object variable in constructor?
body: <p>While creating an object, can we declare and initialize object variable in <code>constructor</code>?</p>
  
  <p>I am creating an object based on XML. XML format is output of previous system and is dynamic. </p>
  
  <p>Hence object variable is based on elements. it will be better if I declare variable in constructor.</p>
  
  <p>In the below code can we declare temp as object variable.</p>
  
  <p>For example:</p>
  
  <pre><code>public class A
  {
      public A()
      {
          HashMap&lt;String, Object&gt; temp = new HashMap&lt;String, Object&gt;;
      }
  }
  </code></pre>
  
  <p>I could not find any sample code for this ideology.<br>
  Any suggestions?</p>