new关键字创建的对象的实例化过程

package com.yingcheng1101.object_oriented.newobject;

//用于给Strudent,Person对象成员属性显示初始化时显示执行了动作的消息类
class InformationDisplay {

	public InformationDisplay(String str) {// 对象初始化时打印指定的消息
		System.out.println(str);
	}

}

public class Student extends Person {

	private InformationDisplay behavior = new InformationDisplay("behavior的显示初始化");

	{// 构造代码块
		behavior = new InformationDisplay("Student构造代码块对behavior的操作");
	}

	Student() {// 构造函数
		super();// super()语句的执行说明Student类构造函数的执行
		// 在super()从Person类的构造函数返回来之后,立马就完成了behavior的显示初始化话动作
		// 之后就是Student构造代码块的执行
		behavior = new InformationDisplay("Student构造函数语句的开始执行");// 这时才开始构造函数里面语句的执行
		System.out.println("Student Constructor over");
	}

	public static void main(String[] args) {
		new Student();

	}

}

class Person {

	private InformationDisplay action = new InformationDisplay("action的显示初始化");

	{// 构造代码块
		action = new InformationDisplay("Person构造代码块对action的操作");
	}

	// Student对象通过super()访问父类的构造函数
	Person() {// 构造函数
		// 在super()从Object类的构造函数返回来之后,立马就完成了action的显示初始化话动作
		// 之后就是Person构造代码块的执行
		action = new InformationDisplay("Person构造函数语句的开始执行");// 这时才开始构造函数里面语句的执行
		System.out.println("Person Constructor over");
	}

}
// action的显示初始化
// Person构造代码块对action的操作
// Person构造函数语句的开始执行
// Person Constructor over
// behavior的显示初始化
// Student构造代码块对behavior的操作
// Student构造函数语句的开始执行
// Student Constructor over
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值