package temp; final class Counter { private static int cnt; public Counter() { cnt++; } public static int show() { return(cnt); } } final public class Main { public static void main(String[] args) { for (int i=0;i<50;i++) { Counter counter=new Counter(); } /*for (int i=0;i<50;i++) Counter counter=new Counter();*/ System.out.print("\nNumber of objects created:->"+Counter.show()+"\n\n"); } }
for
Counter
{/*.../}
counter
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)