java继承的的类之执行顺序我写了一个小demo方便自己记忆。
</pre></p><p>这里是自己学的Person基类</p><p><pre name="code" class="java">package com.john.entites;
public class Person {
public static int id;
static{
id=1;
System.out.println("person static..");
}
protected String sex;
{
System.out.println("person non-static..");
sex="male";
}
public Person() {
Class clzz=this.getClass();
System.out.println("this is person's construtor..."+"class:"+clzz);
}
}
下面是子类Student
package com.john.entites;
public class Student extends Person {
static{
System.out.println("Student static..");
}
protected String sex;
{
System.out.println("Student non-static..");
}
public Student() {
System.out.println("this is Student's construtor...");
}
public static void main(String[] args) {
Student s=new Student();
}
}
结果输出如下:
person static..
Student static..
person non-static..
this is person's construtor...class:class com.john.entites.Student
Student non-static..
this is Student's construtor...