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

Consider the following declarations. public class Player { private double myRati

ID: 3643469 • 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?

A.) I only
B.) II only
C.) III only
D.) I and II
D.) 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()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote