1、父类
package org.e101.com;
public class Father {
static{
System.out.println("Father里面static静态块");
}
{
System.out.println("Father普通块");
}
public Father(){
System.out.println("Father的构造方法");
}
public void fs(){
System.out.println("Father里面的f方法!");
}
}
2、子类
package org.e101.com;
public class Son extends Father {
static{
System.out.println("Son里面的static静态块");
}
{
System.out.println("Son普通块");
}
public Son(){
System.out.println("Son的构造方法");
}
public void fs(){
System.out.println("Son里面的s方法!");
}
}
3、测试类
package org.e101.com;
public class TestFS {
public static void main(String[] args){
Son s=new Son();
s.fs();
}
}
4、输出结果是:
Father里面static静态块
Son里面的static静态块
Father普通块
Father的构造方法
Son普通块
Son的构造方法
Son里面的s方法!
总结:
1、Static最先输出,从父类到子类。
2、普通块高于构造方法。但是普通快与构造方法不能分开(也是从父类开始输出)。
3、而方法的覆盖是就近原则,先找子类。没有再找父类。