I want to print true, in the main method, if the member variable is off. How do I do this without changing the types from void to boolean as off needs to remain void.
The code for the SmartDevice
class is here
public class SmartDevice extends Device {
private boolean member;
public SmartDevice() {
}
@Override
public void on() {
}
@Override
public void off() {
}
}
The code where I need the tweek,
public class TestDevice {
public static void main(String[] args) {
//smart device
SmartDevice smartDevice = new SmartDevice();
//up casting
Device upCastedSmartDevice = new SmartDevice();
//down casting
Device device = new SmartDevice();
SmartDevice downCastedSmartDevice = (SmartDevice) device;
//call methods
smartDevice.on();
smartDevice.off();
//passing devices into switch methods
System.out.println();
//smart device
aSwitch.turnOn(smartDevice);
aSwitch.turnOff(smartDevice);
System.out.println();
//down casted smart device
aSwitch.turnOn(downCastedSmartDevice);
aSwitch.turnOff(downCastedSmartDevice);
System.out.println();
//up casted smart device
aSwitch.turnOn(upCastedSmartDevice);
aSwitch.turnOff(upCastedSmartDevice);
System.out.println();