【发布时间】:2015-10-20 13:36:45
【问题描述】:
我知道有很多关于这个话题的问题。 我有两个过程调用 arrPrint 方法。
第一个程序:
public class Test {
public static void main(String args[]) {
int[] arr = new int[5];
arr = new int[] { 1, 2, 3, 4, 5 };
Test test = new Test();
test.arrPrint(arr);
}
public void arrPrint(int[] arr) {
for (int i = 0; i < arr.length; i++)
System.out.println(arr[i]);
}
}
第二道工序:
public class Test {
public static void main(String args[]) {
int[] arr = new int[5];
arr = new int[] { 1, 2, 3, 4, 5 };
arrPrint(arr);
}
public static void arrPrint(int[] arr) {
for (int i = 0; i < arr.length; i++)
System.out.println(arr[i]);
}
}
哪种方法最好,为什么?
【问题讨论】:
-
为什么需要大量的方法来调用实例方法?想问哪个好? :)