This time I would like to know what would be the smartest and cleanest way to create a program that says how many objects have been created in a class .
I have tried to do it in the following way:
/*Crear un programa que le permita ver cuantos objetos se han creado de una clase
public class CounterObjects {
static int contador;
public static void main(String[]args){
ContadorObjetos obj1=new ContadorObjetos();
ContadorObjetos obj2=new ContadorObjetos();
System.out.println("Actualmente existen "+contador+"objetos en esta clase");
}
}
But actually the counter variable gives me 0 . I have heard that it could be done with an Array ... but I prefer to make sure and ask around here.
I appreciate your clear and understandable answers. Thanks in advance