java 程序加载过程---1-类直接调用静态方法(func1)
类在调用静态方法之前,加载顺序如下
Step1 :父类类中静态变量(类变量)
Step2 :父类中静态代码块
Step3 :子类的中静态变量(类变量)
Step4 :子类中的静态代码块
Step5: 执行调用的静态方法(func1)
class FatherStaticTest
{
public static int fi=100;
public int fii=200;
static
{
System.out.println("fi is"+fi);
}
{
System.out.println("fii is "+fii);
}
}
public class StaticTest extends FatherStaticTest {
public static int k=0;
public static int i=print("i");
public static int n=99;
public int j=print("j");
{
print("构造块");
}
static
{
print("静态块");
}
public static int print(String s)
{
System.out.println(++k+":"+s+"\ti="+i+"\tn="+n);
++n;
return ++i;
}
public StaticTest(String s)
{
System.out.println(++k+":"+s+"\ti="+i+"\tn="+n);
++i;
++n;
}
public static void main(String[] args) {
StaticTest.print("ben");
}
}
执行结果如下
D:\myjava>java StaticTest
fi is100
1:i i=0 n=0
2:静态块 i=1 n=99
3:ben i=2 n=100
D:\myjava>