Question: Consider the following code and answer the following question / / Interface interface Engine { void start ( ) ; void stop ( ) ;

Consider the following code and answer the following question
// Interface
interface Engine {
void start();
void stop();
}
abstract class Vehicle {
private Engine engine;
public Vehicle(Engine engine){
this.engine = engine;
}
public void startEngine(){
engine.start();
}
public void stopEngine(){
engine.stop();
}
// Other common vehicle methods
}
class Car extends Vehicle {
private String model;
public Car(String model, Engine engine){
super(engine);
this.model = model;
}
// Car-specific methods
}
class Bike extends Vehicle {
private String type;
public Bike(String type, Engine engine){
super(engine);
this.type = type;
}
// Bike-specific methods
}
interface ElectricVehicle extends Engine {
void charge();
}
class ElectricCar extends Car implements ElectricVehicle {
public ElectricCar(String model){
super(model, null); // Engine can be null for electric cars
}
@Override
public void charge(){
// Charging logic for electric cars
}
}
Which one of the following answers are incorrect (Please check all that apply):
a.
A composition relationship exists between Car and Vehicle
b.
ElectricVehicle is a subclass of Engine
c.
Engine is a subclass of Vehicle
d.
Class Vehicle realizes the interface Engine
e.
ElectricVehicle is realized by ElectricCar
f.
Bike is a subclass of Engine

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!