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

来源:互联网 发布:淘宝卖家的信誉等级 编辑:程序博客网 时间:2024/06/06 03:02
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
原创粉丝点击