Showing posts with label Number of objects created. Show all posts
Showing posts with label Number of objects created. Show all posts

Friday, December 25, 2020

How to get the number of objects created in JAVA

Program to get the number of objects created in JAVA

public class Main

{

    static int i=0;

    public Main()

    {

        i++;

    }

    public Main(String name)

    {

        i++;

    }

public static void main(String[] args)

{

    Main m=new Main();

    Main m1=new Main("Balaji");

    System.out.println(i);

}

}

Output:

2