类的加载顺序



package com.fea.test.init;

public class Father {
static{
System.out.println("Father_静态初始化块");
}
public static String static_str="Father_静态字段";
{
System.out.println("Father_初始化块");
}
public String str="Father_字段";
public Father(){
System.out.println("Father_构造函数Father()");
}
public Father(String str){
System.out.println("Father_构造函数Father(String str)");
}
}


******************************************************************************

package com.fea.test.init;

public class Child extends Father {
static{
System.out.println("Child_静态初始化块");
}
public static String static_str="Child_静态字段";
{
System.out.println("Child_初始化块");
}
public String str="Child_字段";
public Child(){
System.out.println("Child_构造函数Child()");
}
public Child(String str){
System.out.println("Child_构造函数Child(String str)");
}
public static void main(String[] args) {
new Child();
/**
*
* ***************************
* * *
* *1.父类的静态变量或者静态块 *
* *2.父类的静态变量或者静态块 *
* *3.父类的静态变量或者静态块 *
* *.......... *
* **********|****************
* |
* ***************************
* * *
* *4.子类的静态变量或者静态块 *
* *5.子类的静态变量或者静态块 *
* *6.子类的静态变量或者静态块 *
* *.......... *
* **********|****************
* |
* ***************************
* * *
* *7.Object的初始化, *
* *8.父类的非静态变量或者代码块 *
* *9.父类的非静态变量或者静态块 *
* *10.父类的非静态变量或者静态块 *
* *.......... *
* *11父类的构造函数(在子类构造 *
* *函数中调用的父类构造函数, *
* *默认为无参构造函数) *
* **********|****************
* |
* ***************************
* * *
* *12.子类的非静态变量或者代码块 *
* *12.子类的非静态变量或者静态块 *
* *13.子类的非静态变量或者静态块 *
* *.......... *
* *14子类的构造函数 *
* **************************
*
*
*
*
*
*
*
*继承体系的类加载,先加载父类的静态变量或者静态块,然后加载子类的静态变量或者静态块,
*在父类或者子类中,会按照静态变量或者静态块在类中的先后顺序而先后加载
*静态变量或者静态块初始化以后,会初始化父类的非静态变量或者非静态代码块(顺序和它们
*在类中的出现的先后顺序一样)初始化父类的构造函数,然后是子类的.
*
*
*/

}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值