class ClassLoaderTest{
static {
System.out.println(" 执行静态 块 static block ");
}
public static int age=getAge();
public String str=getString();
public ClassLoaderTest(){
System.out.println(" 执行 构造方法 ClassLoaderTest()");
}
public static int getAge(){
System.out.println("执行 getAge() ,给类变量age赋值");
return 1;
}
public static String getString(){
System.out.println(" 执行 getString(),给实例变量str赋值");
return "String ";
}
{
System.out.println(" 执行实例 块 block ");
}
}
public class ClassLoaderTest1
{
public static void main(String[]args)
{
ClassLoaderTest c1;
System.out.println("new之前的结果");
c1=new ClassLoaderTest();
System.out.println("new之后的结果");
}
}
static {
System.out.println(" 执行静态 块 static block ");
}
public static int age=getAge();
public String str=getString();
public ClassLoaderTest(){
System.out.println(" 执行 构造方法 ClassLoaderTest()");
}
public static int getAge(){
System.out.println("执行 getAge() ,给类变量age赋值");
return 1;
}
public static String getString(){
System.out.println(" 执行 getString(),给实例变量str赋值");
return "String ";
}
{
System.out.println(" 执行实例 块 block ");
}
}
public class ClassLoaderTest1
{
public static void main(String[]args)
{
ClassLoaderTest c1;
System.out.println("new之前的结果");
c1=new ClassLoaderTest();
System.out.println("new之后的结果");
}
}