亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于set和get方法和老師寫的代碼一樣,為什么就是運行不了,求大神指明錯誤?


https://img1.sycdn.imooc.com//5c6bbdd80001849310030451.jpg

https://img1.sycdn.imooc.com//5c6bbdd80001508311830512.jpg

第九行錯誤顯示:the method setCore(int) is undefined for the type Car.

第十行錯誤顯示:the method getCore(int) is undefined for the type Car.


正在回答

3 回答

public class Car{

? ? ? ?? private int core;

? ? ? ?? public void setCore(int core){

? ? ? ? ? this.core = core;

}

? ? ? ?? public int getCore(){

? ? ? ?? return this.core

}

? ? ? ?? Car hello = new Car();

? ? ? ?? System.out.print(hello.core(6));


0 回復 有任何疑惑可以回復我~
#1

霸氣小肆毛 提問者

謝謝大佬,你的這個方法我懂了。 我還想再弱弱的問一下,為啥我之前得方法是錯誤的啊,我想知道錯在哪里,我好像看老師也這樣寫的。
2019-02-19 回復 有任何疑惑可以回復我~

不是,你自己的類名是Inicar,創建類的對象也是 ?IniCar? hello = new? IniCar();

0 回復 有任何疑惑可以回復我~
#1

城序圓

inicar是測試類,,,
2019-03-06 回復 有任何疑惑可以回復我~

代碼我看著沒問題,你應該是沒保存,保存一下再運行

0 回復 有任何疑惑可以回復我~
#1

霸氣小肆毛 提問者

明白了,謝謝!
2019-02-19 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

關于set和get方法和老師寫的代碼一樣,為什么就是運行不了,求大神指明錯誤?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號