Assume there is a class AirConditioner that supports the following behaviors: turning the air conditioner on and off. The following methods provide these behaviors: turnon and turnoff. Both methods accept no arguments and return no value. Assume there is a reference variable officeAC of type AirConditioner. Create a new object of type AirConditioner and save the reference in officeAC. After that, turn the air conditioner on using the reference to the new object. 2. Assume there is a class AirConditioner that supports the following behaviors: turning the air conditioner on and off, and setting the desired temperature. The folowing methods provide these behaviors: turnon and turnoff, which accept no arguments and return no value, and setTemp, which accepts an int argument and returns no value. Assume there is a reference variable officeAC of type AirConditioner. Create a new object of type AirConditioner and save the reference in officeAC. After that, use the reference to turn on the new air conditioner object and set the desired termperature to 69 degrees

Answer :

mahamnasir

Answer:

1)

officeAC = new AirConditioner();

officeAC.turnOn();

2)

officeAC = new AirConditioner();

officeAC.turnOn();

officeAC.setTemp(69);  

Explanation:

1)

In the first statement a new object of the class AirConditioner whose reference is assigned to the officeAC. new is a keyword which creates an object of the class.

Next statement uses the method turnOn(). Reference to the new object officeAC is used to invoke this method turnOn().

2) The first two statements works the same as in 1)

The last statement invokes a method setTemp() using the reference variable and passes the value 69 to this method to set the desired temperature.

Other Questions