416,837 views
1 vote
1 vote
Consider the following code snippet:

public class Vehicle
{
. . .
public void setVehicleClass(double numberAxles)
{
. . .
}
}
public class Auto extends Vehicle
{
. . .
public void setVehicleClass(int numberAxles)
{
. . .
}
}
Which of the following statements is correct?


a. The Auto class overrides the setVehicleClass method.
b. The Vehicle class overrides the setVehicleClass method.
c. The Auto class overloads the setVehicleClass method.
d. The Vehicle class overloads the setVehicleClass method.

User Alexander Lucas
by
2.9k points

1 Answer

13 votes
13 votes

Answer:

c. The Auto class overloads the setVehicleClass method.

Step-by-step explanation:

In this snippet of code the Auto class overloads the setVehicleClass method. This is because if a super-class and a sub-class have the same method, the sub-class either overrides or overloads the super-class method. In this case the sub-class Auto is overloading the setVehicleClass method because the parameters are different. The Auto class methods parameter are of type int while the super-class methods parameter are of type double. Therefore, it will overload the method if an int is passed as an argument.

User MJMortimer
by
3.0k points