For the java class, what are the differences between using "new" inside the constructor and using "new" outside the class? Take an example as follow,
abstract class PowerStat{
final int numOfComponent = UserProperty.numOfComponent;
final int windowSize = 8;
CircularFifoQueue<ArrayList<Double>> movingEnergy;
CircularFifoQueue<Double> movingStartTimes;
CircularFifoQueue<Double> movingEndTimes;
private double [] maxPower = new double[numOfComponent];
private double [] minPower = new double[numOfComponent];
public ArrayList<Double> intervalEnergy = new ArrayList<Double>(numOfComponent);
private ArrayList<UsageNode> usageList = new ArrayList<UsageNode>();
public PowerStat(){
setUsageList(new ArrayList<UsageNode>());
for (int i = 0; i < numOfComponent; i++) {
intervalEnergy.add(0.0);
}
movingEnergy = new CircularFifoQueue<ArrayList<Double>>(windowSize);
movingStartTimes = new CircularFifoQueue<Double>(windowSize);
movingEndTimes = new CircularFifoQueue<Double>(windowSize);
}
}
maxPower is created in the class outside the constructor. However, movingEnergy is instantiated inside the constructor. What are the differences between these two methods.