import java.util.*;
public class BookTest {
public static void main(String[] args) {
ArrayList aList = new ArrayList();
Book b1 = new Book("Catcher In The Rye");
Book b2 = new Book("Crime and Punishment");
aList.add(b1);
aList.add(b2);
for (int i = 0; i < aList.size(); i++)
{
// System.out.println(aList.get(i).getName()); THIS WON'T WORK
Book b = (Book) aList.get(i); // ArrayList object must be typecast as Book
System.out.println(b.getName());
}
System.out.println("There are " + Book.getCount() + " books.");
}
}
0 Comments:
Post a Comment
<< Home