Subject description:
Source:
. 1 public class objectCount { 2 static int CNT = 0 ; . 3 public objectCount () . 4 { . 5 CNT ++ ; . 6 } . 7 public static void the display () . 8 { . 9 . The System OUT .println ( " you have created " + CNT + " th Object " ); 10 } . 11 public static void main (String [] args) { 12 is // TODO Auto-generated method stub 13 objectCount obj1 = new objectCount(); 14 objectCount obj2 = new objectCount(); 15 objectCount obj3 = new objectCount(); 16 objectCount obj4 = new objectCount(); 17 display(); 18 objectCount obj5 = new objectCount(); 19 objectCount obj6 = new objectCount(); 20 objectCount obj7 = new objectCount(); 21 display(); 22 objectCount obj8 = new objectCount(); 23 objectCount obj9 = new objectCount(); 24 display(); 25 } 26 27 }
Ideas:
Static variable count accumulated in the constructor to manipulation variable.
operation result: