I'm looking to implement identifier generator for all new objects created and assign value to them. What am I missing in the below code?
public abstract class Figure {
private static int counter = 0;
private int number;
public Figure() {
}
public static Square createSquare(double a) {
return new Square(a);
}
public static int getCounter() {
return counter;
}
public static void setCounter(int counter) {
Figure.counter = counter;
}
public int getNumber() {
return number = ++Figure.counter;
}
}
You should set the number in the static method invocation.