父类与子类加载情况测试用例
学习用
public class OwTest {
public static void main(String[] args) {
Father people = new Child();
}
}
class Father{
static {
System.out.println("父类加载静态代码块");
}
Father(){
System.out.println("父类构造方法");
}
public static void stPrintF(){
System.out.println("父类静态方法");
}
public int printNum(int a){
System.out.println(a);
return a;
}
public void prTest(){
System.out.println("父类方法");
}
protected void ptMethod(){
System.out.println("父类protected类型方法");
}
}
class Child extends Father{
static {
System.out.println("子类加载静态代码块");
}
Child(){
System.out.println("子类构造方法");
}
public static void stPrintC(){
System.out.println("子类静态方法");
}
public int printNum(int a){
System.out.println("子类重写方法");
return a;
}
public void pr(){
System.out.println("子类普通方法");
}
public void ptMethod(){
System.out.println("子类重写父类protected方法,访问权限大于等于父类被重写的方法");
}
}
创建Child对象时,父类与子类的加载顺序:
|