class Counter {
static int counter = 0;
public Counter() {
counter++;
}
public int ShowObjectNumber() {
return counter;
}
}
public class MyClass {
public static void main(String[] args) {
Counter o1 = new Counter();
System.out.println(o1.ShowObjectNumber());
Counter o2 = new Counter();
System.out.println(o2.ShowObjectNumber());
Counter o3 = new Counter();
System.out.println(o2.ShowObjectNumber());
}
}
/*
run:
1
2
3
*/
}
/*
run:
1
2
*/