class Fu19
{
Fu19(){
System.out.println("fu constructor run");
show();
}
void show()//被覆盖,运行子类的。
{
System.out.println("hehe");
}
}
class Zi19 extends Fu19
{
int num = 9;
{
System.out.println("constructor ..."+num);
}
Zi19()
{
super();
//显示初始化
//构造函数初始化
System.out.println("Zi constructor..."+num);
}
//运行结果发现 构造代码块在构造函数之前 所以我们直观的认为构造代码块先于构造函数之前执行
void show()
{
System.out.println("Zi show ..."+num);
}
}
public class Zongjie2 {
public static void main(String[] args) {
new Zi19();
}
}
对象的初始化过程
最新推荐文章于 2022-07-17 20:50:06 发布