1. 程式人生 > >java編譯期常量 static final

java編譯期常量 static final

複製程式碼
package testPage;

class InitalizedClass {
    static {
        System.out.println("You have initalized InitalizedClass!");
    }
       //和上面的例子唯一的差異就是此處的變數INITIALIZED_VARIBLE被宣告為final
    public final static int INITIALIZED_VARIBLE = 1;

}

public class TestInitializeClass {
    public static void main(String[] args) {
        System.out.println(InitalizedClass.INITIALIZED_VARIBLE);
    }
    
/** * 輸出結果為: * 1 */ }
複製程式碼