First, the experimental requirements
using the class's static fields and constructors, we can track the number of objects created by a class. Write a class that can query it at any time " How many objects have you created?" ".
Second, design ideas
1, create a class Find;
2, define a static integer variable i, so that its record creation of the number of objects;
3, define a function getnum () in the program, so that it returns the measurement value i;
4. Number of output object creation.
Third, the process flow chart
Iv. Source Code
public class Find
{
static int i;
Public Find ()
{
i++; Every object that creates a class I plus 1
}
static int Getnum ()
{
return i;
}
public static void Main (string[] args)
{
Find F1 = new Find ();
Find F2 = new Find ();
Find F3 = new Find ();
Find F4 = new Find ();
Find F5 = new Find ();
System.out.println ("Number of objects created:" +find.getnum ());
}
}
V. Results
Use the static fields and constructors of the class to implement the creation of the object of the class with a Java program