Last active
June 20, 2022 09:07
-
-
Save adityasuseno/048163849c29c17d851a8133e793f12b to your computer and use it in GitHub Desktop.
OOP Practice using Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LightBulb { | |
boolean state; | |
public LightBulb() { | |
state = false; | |
} | |
public void turnOn() { | |
this.state = true; | |
this.printState(); | |
} | |
public void turnOff() { | |
this.state = false; | |
this.printState(); | |
} | |
public void printState() { | |
if (state == true) { | |
System.out.println("Lightbulb is ON"); | |
} | |
else { | |
System.out.println("Lightbulb is OFF"); | |
} | |
} | |
public static void main(String[] args) { | |
LightBulb bathroom = new LightBulb(); | |
bathroom.printState(); | |
bathroom.turnOn(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment