1. If the class provides a custom construction method, it will cause the system to no longer provide a default construction method
2, code output results:100
300
The rule of field initialization is that if the newly created variable is not assigned an initial value, the default constructor is automatically called to assign the initial value, and if it is assigned, it is assigned.
3. Operation Result
static initialization block of Root
static initialization block for Mid
static initialization block of the Leaf
common initialization block for Root
The parameterless constructor of Root
Normal initialization block for Mid
parameter-free constructors for Mid
The parametric constructor for Mid, with parameter values:Java Initialization sequence Demo
ordinary initialization blocks of the Leaf
Execution the Leaf's constructor
Parse: Call the static initialization block of the parent class first, call the static initialization block of the subclass, call the static initialization block after calling the normal initialization block and constructor of the parent class, call the normal initialization block and the constructor of the subclass respectively.
4. An instance member who wants to access a class in a static method can define a static object in the method so that the static method can access the instance members of the class.
5 . See how many objects have been created
Code implementation:
Public class Objictnumber
{
int number;
Public Objictnumber ()
{
++number;
System. out. println (" currently created " +number+ " objects ");
}
Public Static void Main (String[]args)
{
@SuppressWarnings ("unused")
Objictnumber obj=New objictnumber ();
}
}
04 of the hands-on brain in Java