一道简单的JAVA题,但是没太理解题意。帮忙看一下
已知动态数组(ArrayList)有一个student对象但是学生对象里面的score属性没有值,请将student对象的score属性赋值,然后从动态数组里面取出学生对象,打印学生对象 我实在是搞不弄这个题 出的有什么意义,按我的写发就是以下代码,似乎太简单了
程序代码:import java.util.*;
class Student {
String name = "张三";
String sex = "男";
int id = 1;
int score;
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
public class Arr {
public static void main(String[] args) {
Student student = new Student();
ArrayList arr = new ArrayList();
arr.add(student);// ArrayList中存有一个没有score的Student的类对象
new Arr().Info(arr);
}
public void Info(ArrayList arr){
Student s = (Student) arr.get(0);//得到这个对象
s.setScore(90); //给score赋值
System.out.println("学号:"+s.id);
System.out.println("姓名:"+s.name);
System.out.println("性别:"+s.sex);
System.out.println("成绩:"+s.getScore());
}
}








