2.5k views
18 votes
The Bike and EBike classes are implemented as shown by the code below.public class Bike

{
private String make;
private int numGears;
private double tirePressure;
public Bike(String m, int g, double t)
{
make = m;
numGears = g;
tirePressure = t;
}
public void pumpTire()
{
tirePressure += 5.0;
}
}
public class EBike extends Bike
{
private int batteryLevel;
public EBike(String m, int g, double t, int b)
{
super(m, g, t);
batteryLevel = b;
}
public void chargeBattery()
{
batteryLevel++;
}
}
Suppose that the following declarations are made in a separate class.
Bike bike1 = new Bike("Clasic Cycle", 16, 65.0);
Bike bike2 = new EBike("Big EZ", 8, 72.0, 96);
EBike bike3 = new Bike("E-xtreme", 12, 80.0, 44);
Assuming the above three lines compile without error, which of the following statements will cause an error when compiled?
bike3.pumpTire();
bike2.pumpTire();
bike2.chargeBattery();
bike1.pumpTire();
bike3.chargeBattery();

1 Answer

4 votes

Answer:

bike3.chargeBattery();

Step-by-step explanation:

The Bite class is the super or parent class of the Java program while the Ebike class is the subclass or child class inheriting from the super-class. The Bike class defined methods can be used by the object instance of the Ebike class, but the method in the Ebike class cannot be used by the parent class "Bike".

User Rick Westera
by
3.1k points