You have a class named AirConditioner that has a private boolean field named on. It has method named turnOn that sets the field to true and one named turnOff that set it to false. It also has a method named isOn that returns the value of the on field. You have made an object of this class named myAC. If it is not already on, you want the AC on. Fill in the blank to make this happen.
if (!myAC.isOn()) {
___________________
}
The answer is : myAC.turnOn()
Explanation:-
Firstly, if AC is not on then myAC.isOn() will return false which on putting not before false will convert it to true i.e. (!myAC.isOn()) = true . So we go inside if condition only when AC is not on.
Now as we can call the methods using the object of class , in this case it is myAC (example of calling method - inside if condition i.e. myAC.isOn() )
Since turnOn method sets the boolean field to true , therefore we are making a call to turnOn() method using myAC object of class to turn On the AC if it is not already on , as required in the question.
Get Answers For Free
Most questions answered within 1 hours.