編輯:是否有可能或有用的初始化類外的變量? 例如,如果我有這樣的代碼:是否可以在類之外初始化變量?
static int example = 1;
public class test {
public static void main(String []args) {
System.out.println("I have " + example + " question!");
}
還是更多有用做到這一點就像這樣:
public class test {
static int example = 1;
public static void main(String []args) {
System.out.println("I have " + example + " question!");
}
如果這兩種方式都是可能的,有什麼區別? 感謝您提前
你的第一個例子不會編譯。 –
你試過了嗎? – shmosel
這兩個示例都不會編譯 – baao