Re: [問題] static method

看板java作者 (無)時間19年前 (2006/06/19 18:00), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/8 (看更多)
※ 引述《qrtt1 (隱者)》之銘言: : ※ 引述《hpeter (hpeter)》之銘言: : : 小弟覺得 因為被 static function 用到的東西 : : 一定要有static 之修飾 : 因為你沒有正確產生test物件, 所以不能呼叫test的方法 : public class test { : public static void main(String args[]) { : System.out.print(new test().more(2, 4, 4, 4)); : } : public int more(int... num) { : int total = 0; : for (int a : num) : total += a; : return total; : } : } 還有問題 雖然沒產生物件 但是在同class 底下 使用function還要加個static 一直想不出為什麼一樣都是class下的member function還要這樣做呢? 謝謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.221.120.127
文章代碼(AID): #14bdMnI2 (java)
討論串 (同標題文章)
文章代碼(AID): #14bdMnI2 (java)