Question 13
Consider the Java code segment given below.
class BookList { private class Book implements Printable { private String title; public Book(String t) { title = t; } public void print() { System.out.println("Book: " + title); } }
private class BookIterator implements Iterable { private int idx; public BookIterator() { idx = -1; } public boolean has_next() { return idx < list.length - 1; } public Printable get_next() { idx++; return list[idx]; }
}
public Iterable getIterator() { return new BookIterator(); }
private Book[] list = { new Book("Java Basics"), new Book("Data Structures"), new Book("Design Patterns"), new Book("Algorithms"), new Book("Software Engineering") };}
public class TestBooks { public static void main(String[] args) { BookList myBooks = new BookList(); Iterable it = myBooks.getIterator(); while(it.has_next()) { it.get_next().print(); } }}From the following options, identify the appropriate definitions of Iterable and Printable.