Consider this class:
public class Book
{
private String title;
private String author;
private boolean checkoutStatus;
public Book(String bookTitle, String bookAuthor)
{
title = bookTitle;
author = bookAuthor;
checkoutStatus = false;
}
/** Change checkout status. */
public void changeStatus()
{ checkoutStatus = !checkoutStatus; }
//Other methods are not shown.
}
A client program has this declaration:
Book[] bookList = new Book[SOME_NUMBER];
Suppose bookList is initialized so that each Book in the list has a title, author, and checkout status. The following piece of code is written, whose intent is to change the checkout status of each book in bookList.
for (Book b : bookList)
b.changeStatus();
Which is true about this code?
(A) The bookList array will remain unchanged after execution.
(B) Each book in the bookList array will have its checkout status changed, as intended.
(C) A NullPointerException may occur.
(D) A run-time error will occur because it is not possible to modify objects using the for-each loop.
(E) A logic error will occur because it is not possible to modify objects in an array without accessing the indexes of the objects.