+ 1

Write a java program to print number of objects created for a particular class in your Java program

just create one constructor and declare one static variable in it and increment it when you create a object it will get incremented it gives the number of object that are created for the particular class

7th Apr 2017, 5:51 PM
murali krishna
murali krishna - avatar
3 Answers
+ 5
Not sure if you are trying to answer the question or ask it, but here's the code. class CreatedObjs{ public staic int count; CreatedObjs(){ count++; } } public class Program{ public static void main(String args[]){ CreatedObjs a = new CreatedObjs(); System.out.print(a.count); } } In a real program make the instance variables private, and use a get method.
7th Apr 2017, 6:10 PM
Rrestoring faith
Rrestoring faith - avatar
0
thanks
7th Apr 2017, 6:13 PM
murali krishna
murali krishna - avatar
0
thanks
7th Apr 2017, 6:13 PM
murali krishna
murali krishna - avatar