【JAVA小结】类的属性组的使用

    public class UsingAttribute {
    static String strA = "string-a";
    static String strB;
    static String strC = "string-c";
    static String strD;
    
    static
    {
    	printStatic("before static");
    	strB = "sring-b";
    	printStatic("after static");
    }

    public static void printStatic(String title)
    {
    	System.out.println("------"+title+"-----");
    	System.out.println("strA=\""+strA+"\"");
        System.out.println("strB=\""+strB+"\"");
    }
public static void main(String[] args) {
		// TODO Auto-generated method stub
           
           System.out.println();
           System.out.println("----创建 UsingAttribute 对象 ---");
           System.out.println();
           new UsingAttribute();

	}
    
    public UsingAttribute()
    {
    	print("before constructor");
    	strD="string-d";
    	print("after constructor");
    }

    public static void print(String title)
    {
    	System.out.println("------"+title+"-----");
    	System.out.println("strA=\""+strA+"\"");
        System.out.println("strB=\""+strB+"\"");
        System.out.println("strC=\""+strC+"\"");
        System.out.println("strD=\""+strD+"\"");
    }
}

 

posted @ 2015-10-10 14:59  zhaocundang  阅读(330)  评论(0编辑  收藏  举报