package com.proj.oop;
class Child extends Parent {
public final int age = 12;
static{
System.out.println("static code in Child");
}
{
System.out.println("no-static code in Child");
}
private static void init() {
System.out.println("init in Parent");
}
public Child() {
System.out.println("Child default constructor.");
}
public static void mainchild(String... args) {
Child c = new Child();
System.out.println(c.age);
}
}
class Parent {
static{
System.out.println("static code in Parent");
}
{
System.out.println("no-static code in Parent");
}
private static void init() {
System.out.println("init in Parent");
}
public Parent() {
init();
System.out.println("Parent default constructor.");
}
}
public class LoadSeq {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Child c = new Child();
System.out.println(c.age);
}
}
输出结果如下:
static code in Parent
static code in Child
no-static code in Parent
init in Parent
Parent default constructor.
no-static code in Child
Child default constructor.
12