Insert the missing code in the following code fragment. This fragment is intended to implement a method to assign a value to an instance variable.
public class Vehicle
{
private String model;
private double rpm;
. . .
_______
{
model = modelName;
}
}
a) public void setModel(String modelName)
b) public void getModel()
c) public String getModel()
d) public String setModel(String modelName)

Respuesta :

ijeggs

Answer:

a) public void setModel(String modelName)

Explanation:

Writing methods for a class in java requires the optional access modifier (public, private or protected) followed by the return type (void, int, String etc), this is followed by the method's name and parameter list.

In the options given in the question above, only A and D come close to describing the method however option A is correct because this method is not expected to return a value when called hence return type is void