+ 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
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.
0
thanks
0
thanks