作者justinC (无)
看板java
标题Re: [问题] static method
时间Mon Jun 19 18:02:33 2006
※ 引述《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