Consider the following declaration/ public class CD { private String[] songs; pu
ID: 3643388 • Letter: C
Question
Consider the following declaration/public class CD
{
private String[] songs;
public getSong(int k)
{ return songs[k]; }
// constructor and other methods not shown
}
ArrayList<CD> CDCollection;
Assume that CDCollection has been initialized and several CD 's have been added to it. Which of the following can be used in a client program to reference the third song on the fifth CD in the collection?
A.) CDCollection[4].songs[2]
B.) CDCollection.get(4).songs[2]
C.) CDCollection[4].getSong(2)
D.) CDCollection.get(4).getSong(2)
E.) getSong(2).get(4).CDCollection
Explanation / Answer
D.) CDCollection.get(4).getSong(2) This can be used in a client program to reference the third song on the fifth CD in the collection