The static field of the package class, the number of public class statistics objects {
Static Class Employee
{
static int num;
Public Employee () {
num = num + 1;
}
int sum1 () {
return num;
}
}
public static void Main (String []args) {
Employee A = new Employee ();
Employee B = new Employee ();
Employee C = new Employee ();
Employee D = new Employee ();
Employee E = new Employee ();
Employee F = new Employee ();
SYSTEM.OUT.PRINTLN ("You have created a +employee.num+" object ");
}
}
Because after the constructor of the class has been modified, the initialization object calls only the modified function, so the object is not initialized and the function's arguments should be added so that the object is initialized.
The execution order of static initialization blocks:
Static initialization blocks are performed at the highest priority and can only be performed once. The constructor executes after it, and the constructor is called once without generating the object once.
Non-static initialization of block constructors is performed before. The constructor is the initialization of the object.
Determine the number of class objects