write a variant of the following program which produces the output:
false
false
true
false
true
true
false
false
Your modifications should be restricted to the first class, and should not use the ‘println’ command.
class prg{
public static void main(String[] args) {
Bulb b1 = new Bulb();
b1.flip();
b1.flip();
b1.flip();
b1.flip();
} }
class Bulb {
boolean status;
Bulb () { status=true; }
void flip (){
status = ! status;
System.out.println( status );
}
}
Hints:
- Compile and execute the given program. Inspect the output.
- Try understanding the effect of the different instructions in the body of method ‘main’:
- Try deleting different instructions in the body of ‘main’, and check the outcome.
- Try adding to the body of ‘main’ instructions similar to those that are already there, and check the outcome.