package test;
public class InitSequence{
Tools ts1=new Tools();
{
System.out.println("hello");
}
InitSequence(){
System.out.println("score()");
}
public static void main(String[]args){
System.out.println("call Tools.t4.f(4)in main()");
Tools.t4.f(4);
System.out.println("creating new Tools() in main()");
new Tools();
System.out.println("creating new score() in main()");
new InitSequence();
}
static Tools ts2 =new Tools();
}
class Tools{
Tool t1=new Tool(1);
static Tool t3=new Tool(3);
static{
System.out.println("进入静态初始化块");
t3=new Tool(33);
t4=new Tool(44);
System.out.print("退出静态初始化块");
}
{
System.out.print("进入实例化初始化块");
t1=new Tool(11);
t2=new Tool(22);
System.out.print("退出实例化初始块");
}
Tools(){
System.out.println("Tools()");
t2=new Tool(222);
}
static Tool t4=new Tool(4);
Tool t2=new Tool(2);
}
class Tool{
Tool(int i){
System.out.println("Tool("+i+")");
}
void f(int i){
System.out.println("f("+i+")");
}
}
java数据成员初始化实例
最新推荐文章于 2021-09-25 20:04:00 发布