Quiz Space

Programming Concepts using Java · Quiz 1 · 23 Feb 2025 · January 2025 term

Question 13: Consider the code given below.

Question 13

+7 marksOne correct option

Consider the code given below.

java
interface PlaylistIterator {
public boolean hasNextSong();
public Object getNextSong();
}
abstract class Song {
public abstract void play();
}
class SongPlaylist {
public SongPlaylist() {
private final int count = 3;
private Track[] songs = {new Track("Song A"), new Track("Song B"),
new Track("Song C")};
}
private class Track extends Song {
private String title;
public Track(String title) {
this.title = title;
}
public void play() {
System.out.println("Playing: " + title);
}
}
private class PlaylistIter implements PlaylistIterator {
private int currentIndex;
public PlaylistIter() {
// Constructor
}
public boolean hasNextSong() {
// Check if there is a next song
}
public Object getNextSong() {
// Return the next song
}
}
public PlaylistIterator getIterator() {
return new PlaylistIter();
}
}
public class PlaylistTest {
public static void main(String[] args) {
SongPlaylist playlist = new SongPlaylist();
PlaylistIterator iter = playlist.getIterator();
while (iter.hasnext()){
-----------------------; //LINE 1
}
}
}
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

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

More questions from this paper

  1. Q1Consider the code given below. How many activation records are created while executing this code?
  2. Q2Figure question
  3. Q3Consider the Java code given below. What will the output be?
  4. Q4Consider the code given below. Choose the correct option.
  5. Q5Consider the Java code given below. Choose the correct option.
  6. Q6Consider the code given below that checks whether two players are the same. Method equals is overridden to compare two …
  7. Q7Consider the Java code given below. Choose the correct option.
  8. Q8Consider the Java code given below. What will the output be?
  9. Q9Consider the Java code given below. Choose the correct option.
  10. Q10Consider the Java code given below. Which of the following statements is FALSE?
  11. Q11Consider the Java code given below. Identify the correct option to fill in place of CODE BLOCK, such that the output is…
  12. Q12Consider the Java code given below. Choose the correct option.
  13. Q14Consider the Java program below. Identify the correct option(s) to fill in the blank at LINE 1, such that the output is…
  14. Q15Consider the Java code given below. Identify the correct option(s) to fill in the blank at LINE 1, such that the output…