Question: Consider the following two class definitions. public class Bike { private int numOfWheels = 2; public int getNumOfWheels() { return numOfWheels; } } public class
Consider the following two class definitions.
public class Bike
{
private int numOfWheels = 2;
public int getNumOfWheels()
{
return numOfWheels;
}
}
public class EBike extends Bike
{
private int numOfWatts;
public EBike(int watts)
{
numOfWatts = watts;
}
public int getNumOfWatts()
{
return numOfWatts;
}
}
The following code segment occurs in a class other than Bike or EBike.
Bike b = new EBike(250);
System.out.println(b.getNumOfWatts());
System.out.println(b.getNumOfWheels());
Which of the following best explains why the code segment does not compile?
-
A. The Bike superclass does not have a constructor.
-
B. There are too many arguments to the EBike constructor call in the code segment.
-
C. The first line of the subclass constructor is not a call to the superclass constructor.
-
D. The getNumOfWatts method is not found in the Bike class.
-
E. The getNumOfWheels method is not found in the EBike class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
