不理解对象数组类型作为参数,举一个简单的例子理解一下,谢谢!
class Person{
public String name;
}
public class Test{
public static void main(String[] args){
String[] arr = new String[2];
Person p1 = new Person();
p1.name = "å¼ ä¸";
Person p2 = new Person();
p2.name = "æå";
arr[0] = p1;
arr[1] = p2;
}
}
public String name;
}
public class Test{
public static void main(String[] args){
String[] arr = new String[2];
Person p1 = new Person();
p1.name = "å¼ ä¸";
Person p2 = new Person();
p2.name = "æå";
arr[0] = p1;
arr[1] = p2;
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2018-04-05
呵呵,main方法中的str不就是个对象数组么,String 数组。本回答被网友采纳
第2个回答 2013-04-14
public void printArray(int[] arr){
for(int i=0; i< arr.length; i++){
System.out.println(arr[i]);
}
}
这就叫吧数组作为参数。
够清楚了吗?
for(int i=0; i< arr.length; i++){
System.out.println(arr[i]);
}
}
这就叫吧数组作为参数。
够清楚了吗?
第3个回答 2013-04-13
创建对象
A a1 = new A();
A a2 = new A();
A a3 = new A();
A a4 = new A();
A a5 = new A();
A[] as = {a1,a2,a3,a4,a5};
将as作为参数
A a1 = new A();
A a2 = new A();
A a3 = new A();
A a4 = new A();
A a5 = new A();
A[] as = {a1,a2,a3,a4,a5};
将as作为参数