In the Toy class below, the raisePrice method is intended to increase the value of the instance variable price by the value of the parameter surcharge. The method does not work as intended.
public class Toy
{
private String name;
private double price;
public Toy(String n, double p)
{
name = n;
price = p;
}
public void raisePrice(double surcharge) // Line 12
{
return price + surcharge; // Line 14
}
Which of the following changes should be made so that the class definition compiles without error and the method raisePrice works as intended?
A. Replace line 14 with surcharge += price;.
B. Replace line 14 with price += surcharge;.
C. Replace line 14 with return price += surcharge;.
D. Replace line 12 with public raisePrice (double surcharge).
E. Replace line 12 with public double raisePrice (double surcharge).



Answer :

Other Questions