Question 13
Consider the code given below.
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 } }}