子類和父類,靜態程式碼塊,程式碼塊呼叫順序
<![endif]-->
class String ;
private age {
out "people static block" }
System. .println( );
People() {
System. .println( );
public ();
this name . = age;
out "people constructor arguments" }
String getName() {
return ;
public setName(String name) {
this name }
String getAge() {
return ;
public setAge(String age) {
this age }
class extends String ;
private grade {
out "student static block" }
System. .println( );
Student() {
super System. .println( );
Student(String schoolName, String grade) {
. = schoolName;
this grade System. .println( );
String getSchoolName() {
return ;
void . = schoolName;
String getGrade() {
return ;
void . = grade;
public Test2 {
public void Student s = Student();
new "aa" "bb" }
通過執行結果 , 那在載入類的時候 , 再載入子類 static 程式碼塊 . 普通程式碼塊 . 類的載入只執行一次 . 而呼叫子類的建構函式都是會先隱式的執行父類的無參建構函式 <FONT style="FONT-SIZE: 12pt" color="black" face=""">.