Question 3
Consider the code given below that searches for a Book in an array. Two Book objects are considered equal if they have the same title and isbn. The equals method needs to be overridden so that the search works correctly.
class Book { private String title; private String isbn;
//constructor to initialize the instance variables
public boolean equals(Object obj) { // CODE BLOCK }}
public class Test { public static void main(String[] args) { Book[] library = { new Book("Effective Java", "111"), new Book("Clean Code", "222"), new Book("Design Patterns", "333") };
Book target = new Book("Clean Code", "222"); boolean found = false;
for (int i = 0; i < library.length; i++) { if (library[i].equals(target)) { found = true; break; } }
if (found) System.out.println("Book Found"); else System.out.println("Book Not Found"); }}Choose the correct option to fill in place of CODE BLOCK so that the output is:
Book Found