新建一个类Student 其中有若干个对象用set方法在另一个新见的类TestStudent中用数
组方式构建Student的若干个对象并对Student类中的对象赋值
你表述不清啊 class Student{
String name;
int age;
String phone;
(这字段封装下)
}
然后在TestStudet 就可以调用,并赋值了
在TestStudent中创建Student类型的数组或者list
Student[] stuArr = new Student[10];
for(int i=0;i<10;i++){
Student temp = new Student();
strArr[i] = temp;
//对Student类中的对象赋值
}
//或者List
List<Student> stuList = new ArrayList<Student>();
for(int i=0;i<10;i++){
Student temp = new Student();
list.add(temp);
//对Student类中的对象赋值
}
public static void main(String[] args) {
Student[] stus=new Student[20];
for(int i=0;i<20;i++){
stus[i]=new Student();
}
TestStudent teststus=new TestStudent (stus);
stus=teststus.getStus();
for(int i=0;i<stus.length;i++){
System.out.println("stus["+i+"]"+"="+stus[i].getName());
}
}
class Student{
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class TestStudent{
private Student[] stus;
public TestStudent(){
}
public TestStudent(Student[] stus){
for(int i=0;i<stus.length;i++){
stus[i].setName("对象"+i);
}
this.stus=stus;
}
public Student[] getStus(){
if(stus!=null){
return this.stus;
}else{
return null;
}
}
}
额,你的问题是什么呢