Hello,
I think this is what you are looking for
Code:
public class Example{
int temp;
Example(){
temp++;
}
public static void main(String[] args){
Example e = new Example();
System.out.println("No. of instances for e : " + e.temp);
Example e2 = new Example();
System.out.println("No. of instances for e : " + e.temp);
System.out.println("No. of instances for e2 : " + e2.temp);
Example e3 = new Example();
System.out.println("No. of instances for e : " + e.temp);
System.out.println("No. of instances for e2 : " + e2.temp);
System.out.println("No. of instances for e3 : " + e3.temp);
}
}
Bookmarks