Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following declaration/ public class CD { private String[] songs; pu

ID: 3643422 • 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