更新时间:2023-01-15 17:09:20
***也是面向对象的方法是创建一个具有姓,名和结果作为属性(实例变量)的类,如下所示:
The best and also Object Oriented approach is to Create a class with surname, forename and result as attributes(instance variables) like below:
class Student{
private String surname;
private String forename;
private String result;
public Details(String surname, String forename, String res){
//initialize properties here
}
}
现在,创建一个仅接受Student
对象的列表.
now, create a List which only accepts Student
Object.
List<Student> list = new ArrayList<Student>();
list.add(new Student("surname", "forname", "pass"));