我知道這個話題有很多問題。 我有兩個過程叫做arrPrint方法。什麼是從Java中的靜態方法調用非靜態方法的最佳方式?
第一個步驟:
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]);
}
}
哪個程序是最好的,爲什麼?
爲什麼你需要很多方法來調用實例方法?問問哪一個更好? :) –