In: Computer Science
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. Fill in the blank to complete the turnOff method.
public void turnOff() { ______________________ }
The given requirement is to fill in the blank to complete the method turnOff , So the C++ code filling the blank is below.
Note: Since the question did not specify the code fill should be in C++ or Java. i have provide both codes as screenshots below after this code section .
void turnOff()
{
on =false;
cout << "AirConditioner is set off. So the variable on is " << on;
}
Full code of C++ for your understanding below
#include <iostream>
using namespace std;
class AirConditioner
{
private:
bool on;
public:
void turnOff()
{
on =false;
cout << "AirConditioner is set off. So the variable on is " << on;
}
};
int main()
{
AirConditioner obj;
obj.turnOff();
return 0;
}
Please find the screen shot of full code in C++ and output below
Please find the full code in java and output below for your understanding
public class Main
{
static class AirConditioner
{
private static boolean on;
public static void turnOff()
{
on=false;
System.out.println(" AirConditioner is set off. So the variable on is "+ on);
}
};
public static void main(String[] args)
{
AirConditioner obj = new AirConditioner();
obj.turnOff();
}
}
Please find the screen shot of full code and output in java below