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 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
This question is related to Java inheritance constructor calling and instance method invocation Lets ... View full answer
Get step-by-step solutions from verified subject matter experts
