求大神指点01
package com.collection;
public class Book {
public String id;
public String name;
public void Book(String id,String name) {
this.id = id;
this.name = name;
}
}
package com.collection;
import java.util.ArrayList;
import java.util.List;
public class ListTest {
public List BookToSelect;
public ListTest(){
this.BookToSelect=new ArrayList();
}
public void BookAdd(){
Book bt=new Book("1.","《三国演义》");//此处编译器报错
BookToSelect.add(bt);
Book temp=(Book) BookToSelect.get(0);
System.out.println("添加了第一本书:"+bt.id+bt.name);
}
public static void main(Sring[] args){
ListTest lt=new ListTest();
lt.BookAdd();
}
}
如果把Book类中的属性设置为private,那么在Book中应该怎么去添加书呢?