bizhen_npu
2016-01-31 10:53
采纳率: 50%
浏览 1.5k
已采纳

java关于ArrayList()的简单问题

package Hope;
import java.util.ArrayList;
import java.util.List;
public class ListTest {
public List coursesToSelec;

/* public ListTest(){
this.coursesToSelect = new ArrayList();
}
*/
coursesToSelect = new ArrayList(); //把上面的内容注释掉,换成这段代码为什么不行?

public void addCourse(){
    Course cr1 = new Course("离散数学",1);
    coursesToSelect.add(cr1);
    Course temp = (Course) coursesToSelect.get(0);
    System.out.println(temp.name+" "+temp.number);

}      

public static void main(String[] args){
    ListTest a = new ListTest();
    a.addCourse();
}

}

package Hope;
public class Course {
String name;
int number;
public Course(String name,int number){
this.name = name;
this.number = number;
}

}

1条回答 默认 最新

相关推荐 更多相似问题