Which modification enables the code fragment to print H…

Given:
class FuelNotAvailException extends Exception { }
class Vehicle {
void ride() throws FuelNotAvailException { //line n1
System.out.println(“Happy Journey!”);
}
}
class SolarVehicle extends Vehicle {
public void ride () throws Exception { //line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws FuelNotAvailException, Exception
{
Vehicle v = new SolarVehicle ();
v.ride();}
Which modification enables the code fragment to print Happy Journey!?

Given:
class FuelNotAvailException extends Exception { }
class Vehicle {
void ride() throws FuelNotAvailException { //line n1
System.out.println(“Happy Journey!”);
}
}
class SolarVehicle extends Vehicle {
public void ride () throws Exception { //line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws FuelNotAvailException, Exception
{
Vehicle v = new SolarVehicle ();
v.ride();}
Which modification enables the code fragment to print Happy Journey!?

A.
Replace line n1 with public void ride() throws FuelNotAvailException {

B.
Replace line n1 with protected void ride() throws Exception {

C.
Replace line n2 with void ride() throws Exception {

D.
Replace line n2 with private void ride() throws FuelNotAvailException {



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Edward

Edward

The answer id D without private.
I mean:
Replace line n2 with void ride() throws FuelNotAvailException {

smh

smh

B. correct answer
Replace line n1 with protected void ride() throws Exception {

Hint. in class SolarVehicle change super ride (); to super.ride (); to get correct answer.