請問下這個代碼為什么在myeclipse中執行不出來
public class HelloWorld {
???
??? String name; // 聲明變量name
?String sex; // 聲明變量sex
?static int age;// 聲明靜態變量age
???
???
?public HelloWorld() { // 構造方法
??System.out.println("通過構造方法初始化name");
??name = "tom";
?}
???
???
?{ // 初始化塊
??System.out.println("通過初始化塊初始化sex");
??sex = "男";
?}
???
?
???? static??? {?? // 靜態初始化塊
??System.out.println("通過靜態初始化塊初始化age");
??age = 20;
?}
???
?public void show() {
??System.out.println("姓名:" + name + ",性別:" + sex + ",年齡:" + age);
?}
???
?public static void main(String[] args) {
???????
???????
??HelloWorld hello = new HelloWorld();// 創建對象
??????? hello.show();// 調用對象的show方法
???????
?}
}
2016-08-07
可以輸出啊
2016-08-07
找到原因了?~