Quiz Space

Programming Concepts using Java · Quiz 1 · 13 Jul 2025 · May 2025 term

Question 8: Consider the code given below. Identify the appropriate s…

Question 8

+7 marksOne correct option

Consider the code given below.

java
interface Navigator {
boolean hasNext();
Object next();
}
abstract class Displayable {
public abstract void show();
}
class BookShelf {
private class Book extends Displayable {
private String title;
public Book(String t) {
title = t;
}
public void show() {
System.out.print(title + ", ");
}
}
private class BookIterator implements Navigator {
private int index;
public BookIterator() {
//Constructor
}
public boolean hasNext() {
// Check if there is a next book
}
public Object next() {
// Return the next book
}
}
public Navigator getNavigator() {
return new BookIterator();
}
private Book[] books = {new Book("Swami"), new Book("Pyre"),
new Book("Palace") };
}
public class LibraryTest {
public static void main(String[] args) {
BookShelf shelf = new BookShelf();
Navigator nav = shelf.getNavigator();
while (nav.hasNext()) {
___________________________________; // LINE 1
}
}
}

Identify the appropriate statement to fill in the blank at LINE 1, such that the output is: Swami, Pyre, Palace,

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 8 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 1 paper sat on 13 Jul 2025, in the May 2025 term (IIT M DIPLOMA AN EXAM QDD2 13 July 2025). It carries 7 marks.

More questions from this paper

  1. Q1Consider the following Java program. When the call stack reaches its maximum depth, which method will be at the top of …
  2. Q2Consider the Java code below. Choose the correct option.
  3. Q3Consider the Java code given below. Choose the correct option to be filled in place of LINE 1 so that the output is: Na…
  4. Q4Consider the Java code given below: What will the output be?
  5. Q5Consider the Java program below. Choose the correct option to fill in place of the CODE BLOCK so that the output is:
  6. Q6Consider the Java code given below. Identify the appropriate option to fill in place of LINE 1 such that the output is:
  7. Q7Consider the Java code given below. Choose the correct option.
  8. Q9Consider the Java code given below. What will the output be?
  9. Q10Consider the following Java code. Choose the correct option.
  10. Q11Consider the Java code given below. Choose the correct option for LINE 1 such that the program generates the following …
  11. Q12Which of the following statements correctly describe interface and specification in software components?
  12. Q13Which among the following statements is/are true about activation records?
  13. Q14Consider the Java code given below. Choose the correct option(s) to fill in the CODE SEGMENT so that the output is: Mal…
  14. Q15Consider the Java code given below. Which of the following statements are correct?