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 Team { private String myName; p

ID: 3643377 • Letter: C

Question

Consider the following declaration.

public class Team
{
private String myName;

public String name()
{ return myName; }
}

Team[] league = new Team[10];

Assume that the elements of the array league have been initialized. Which of the following statements can be used in a client class to print the name of the third team in league to the screen?

A.) System.out.println(league.myName[2]);
B.) System.out.println(league.name()[2]);
C.) System.out.println(league[2].myName);
D.) System.out.println(league[2].name());
E.) System.out.println(league.name(2));

Explanation / Answer

D