Code :
class Obj{ static int count; Obj(){ count++; System.out.print("\nObject "+count+" created..."); } static void showCount(){ System.out.print("\nTotal Object Count : "+count); } } class ObjCount{ public static void main(String args[]){ Obj o1=new Obj(); Obj o2=new Obj(); Obj.showCount(); Obj o3=new Obj(); Obj.showCount(); } }Output :
Object 1 created... Object 2 created... Total Object Count : 2 Object 3 created... Total Object Count : 3Note : Leave a comment if you feel the program is incorrect and/or has errors and/or if the program and its output don't match. Please report about broken links.
No comments:
Post a Comment