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

时间:2022-05-22 10:10:16
    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+"\"");
    }
}