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

5.Consider the following code snippet: public class Vehicle { . . . public void

ID: 3642708 • Letter: 5

Question

5.Consider the following code snippet:
public class Vehicle
{
. . .
public void setVehicleClass(double numberAxles)
{
. . .
}
}
public class Auto extends Vehicle
{
. . .
private void setVehicleClass(double numberAxles)
{
. . .
}
}
What is wrong with this code?
Answer

a.The
extends
reserved word should be replaced with the
implements
reserved word.
b.
A subclass can only override the constructor of its superclass.
c.
A subclass cannot override a
pubic
method by making it
private
.
d. There is nothing wrong with this code.

Explanation / Answer

c. A subclass cannot override a pubic method by making it private Once a superclass declares a method as public, the subclasses may not reduce the visibility to private.

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