Question 14
Consider the Java code given below.
interface Chargeable {
void showChargeStatus();
}
class Laptop implements Chargeable {
public void showChargeStatus() {
System.out.println("Laptop is charging");
}
}
class Mobile implements Chargeable {
public void showChargeStatus() {
System.out.println("Mobile is charging");
}
}
class DeviceList {
private Object[] devices = {new Laptop(), new Mobile()};
public void testDevices() {
for (int i = 0; i < devices.length; i++) {
//LINE-1
}
}
}
public class TestDevices {
public static void main(String[] args) {
DeviceList dL = new DeviceList();
dL.testDevices();
}
}
Identify the appropriate option to fill in place of LINE-1 such that the output is:
Laptop is charging
Mobile is charging
((Chargeable) devices[i]).showChargeStatus();
devices[i].showChargeStatus();
((Laptop) devices[i]).showChargeStatus();
((Mobile) devices[i]).showChargeStatus();