When creating an object, can we declare and initialize the object variable in constructor?
I am creating an XML based object. The XML format is derived from the previous system and is dynamic.
Therefore, an object variable is based on elements. it will be better if I declare a variable in the constructor.
In the code below, we can declare temp as an object variable.
For instance:
public class A
{
public A()
{
HashMap<String, Object> temp = new HashMap<String, Object>;
}
}
I could not find a sample code for this ideology.
Any suggestions?
source
share