Question
The Bike and EBike classes are implemented as shown by the code below. public class Bike { private String make; private int numGears; private double
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++; } }
A new private int variable, currentGear is added to the Bike class. Which of the following describes the best implementation of a changeGear method which would allow the value of currentGear to be changed by instances of the Bike and EBike classes?
A public changeGear method is added to the Bike class only.
A public changeGear method is added to the EBike class only.
A private changeGear method is added to the EBike class only.
A private changeGear method is added to the Bike class only.
A private changeGear method is added to both theBike and EBike classes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started