Public class Init {
Private int age;//non-static initialization of statements <3>
Private Static String name; Static initialization of statements, first initialize static <1.1>
/** static initialization statements and static initialization modules are static (the same level), who first initialize who in front of * *
{/** dynamic initialization module (non-static initialization module) <4>*/
Double width;
float Price;
System. out. println ("Parent class non-static");
}
Static {/** static initialization module <2>*/
int ID;
String pwd;
name = "admin";//when initializing name and assigning value, do not wait for static initialization module <1.2>
System. out. println ("parent class static");
}
private static String name;/** If the statement is placed under the module, it is the same as in the order <1.1>*/
The/** constructor is not executed until all the member variables have been initialized */
Public Init () {
Char Gender = ' C ';//<5>
System. out. println ("parent construct");
}
Public Static void Main (string[] args) {
New Init();
New Child ();
}
}
/**
* Subclass inherits Parent class, subclass and parent class have both static and non-static and constructed
* 1, initialize the parent class static
* 2, Initialize subclass static
* 3, initialize the parent class non-static
* 4, initialize the parent class construction
* 5, initialize subclass non-static
* 6, Initialize subclass constructs
*
* */
class Child extends init{
{
System. out. println ("sub-class non-static");
}
Static {
System. out. println ("Subclass Static");
}
Public Child () {
System. out. println ("sub-class construction");
}
}
Initialization of Java variables