Consider the following declarations. public class Player { private double myRati
ID: 3643376 • Letter: C
Question
Consider the following declarations.public class Player
{
private double myRating;
public double rating()
{ return myRating; }
// constructors, other instance variables and methods not shown
}
public class Partnership
{
private Player p1, p2;
public double rating()
{
// code to return the sum of the ratings for the two players in the partnership
}
// constructors and other methods not shown
}
Consider the following statements.
I. return Player[1].myRating + Player[2].myRating;
II. return p1.myRating + p2.myRating;
III. return p1.rating() + p2.rating();
Which of these statements correctly completes the method rating in the class Partnership?
*ANSWER CHOICES*
A.) I only
B.) II only
C.) III only
D.) I and II
E.) II and III
Explanation / Answer
please rate
Answer is C) III only
Option I is incorrect because no arrays have been decared anywhere also Player is class name and not an instance name. It is syntactically incorrect.
II) is incorrect because private member myRating cannot be directly accessed outside the class. It has to be accessed using the function rating()