以下程序報錯 String 錯了要怎么改?
?public class OK4 {?
?Sring name;//申明變量
name public OK4(){//構造方法
?name="愛慕課";?
?System.out.println("name是:");
?}
?public static void main(String[] agrs){ OK4 hello=new OK4(); System.out.println("name"+hello.name);?
}
?}
?public class OK4 {?
?Sring name;//申明變量
name public OK4(){//構造方法
?name="愛慕課";?
?System.out.println("name是:");
?}
?public static void main(String[] agrs){ OK4 hello=new OK4(); System.out.println("name"+hello.name);?
}
?}
2016-01-26
舉報
2016-01-26
?public class OK4 {?
? ? ? //修改為靜態:static?。樱簦颍椋睿纭。睿幔恚?;
? ? ?String name;//申明變量 ?改:sring 單詞錯誤
? ? ? //修改為靜態:public static?。希耍矗ǎ?/p>
? ? ? ?public OK4(){//構造方法
? ? ? ? ? ? name="愛慕課";?
? ? ? ? System.out.println("name是:");
? ? ? ?}
? ? ? ?public static void main(String[] agrs){?
? ? ? ? ? ? OK4 hello=new OK4();?
? ? ? ? ? ? System.out.println("name"+hello.name); //name 非靜態成員;OK4()非靜態方法
? ? ? ?}
?}
2016-01-26
public class OK4 {
String name; //申明字符串變量 name
public OK4(){//構造方法
name="愛慕課";//初始化塊
System.out.println("通過構造方法初始化name");
}
public void show(){
System.out.print("名稱為:"+name);
}
public static void main(String[] arge){
OK4 hello=new OK4();//創建對象
hello.show();// 調用對象show方法
}
}
2016-01-26
public class OK4 {?
????????public String name ;?????????????????????????????? //申明變量
????????public OK4(){????????????????????????????????????????? //構造方法
?????????name="愛慕課";?
?????????System.out.println("name是:");
?????????}
?????????public static void main(String[] agrs){
????????????????OK4 hello=new OK4(); ???????????????
????????????????System.out.println("name"+hello.name);?
????????}
?}