類與對象問題
package photo.com; public class wshouji { public static void main(String[] args) { // TODO Auto-generated method stub wshouji phone=new wshouji(); } phone.sendmessage(); } 按老師要求寫怎么錯了,也不知道怎么改,是什么問題呢?
package photo.com; public class wshouji { public static void main(String[] args) { // TODO Auto-generated method stub wshouji phone=new wshouji(); } phone.sendmessage(); } 按老師要求寫怎么錯了,也不知道怎么改,是什么問題呢?
2016-03-03
舉報
2016-03-03
package photo.com;
public class wshouji {
public static void main(String[] args) {
// TODO Auto-generated method stub
wshouji phone=new wshouji();
phone.sendmessage();
//因為phone是個局部變量
}
}
2016-03-03
這個是完整的代碼嗎?
如果是的話,首先程序中并沒有實現(xiàn)方法sendmessage()(強迫癥建議:方法名最好寫為sendMessage);
其次,通過對象調(diào)用成員方法時,phone.sendmessage();應該放到創(chuàng)建對象的語句后面,中間檢查是不是多了一個大括號。