Question: public class Carl private int fuel; } 10) Given the following class declarations and code, what is the result when the code in the

public class Carl private int fuel; } 10) Given the following class

public class Carl private int fuel; } 10) Given the following class declarations and code, what is the result when the code in the Test class is run? } public Car() { fuel = 0; } public Car(int g) { fuel=g; } public void addFuel() { fuel++; } public void display() { System.out.print(fuel + " "); } public class RaceCar extends Car{ public RaceCar(int g) { super(2*g); } Test: Car car = new Car(2); Car fastCar = new RaceCar(2): car.display(); car.addFuel(); car.display(); fastCar.display(); fastCar.addFuel(): fastCar.display(); Options: a) 2323 b) 2345 c) 4545 d) The code won't compile. e) You get a runtime error ClassCastException, when fastCar.addFuel() is executed

Step by Step Solution

3.46 Rating (149 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This question is related to Java inheritance constructor calling and instance method invocation Lets ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!