java数据成员初始化实例

来源:互联网 发布:淘宝运营年度计划表 编辑:程序博客网 时间:2024/06/01 03:57
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+")");    }}
0 0
原创粉丝点击