初始化一个类,必须先初始化它的属性
构造一个类对象,必须先构造它的父类对象。
对super()的调用必须是构造方法中的第一个语句 。
package mianxaingduixaing;
/*
*先运行第一级(类),再运行第二级(对象实例等)
* 每一级都是先父类,再子类
* 第一级信息在第一次调用(new或者调用此类)时初始化并且只会初始化一次
* 第二级使用(new对象)一次,执行一次
*/
public class test {
public static void main(String[] args) {
father f=new child();
f=new child();
}
}
class father{
public father(){
System.out.println("father.....");
}
static{//静态的信息只会初始化一次
System.out.println("father2......");
}
}
class child extends father{
public child(){
System.out.println("child.....");
}
static{
System.out.println("child2......");
}
}