Skip to content

Instantly share code, notes, and snippets.

@adityasuseno
Last active June 20, 2022 09:07
Show Gist options
  • Save adityasuseno/048163849c29c17d851a8133e793f12b to your computer and use it in GitHub Desktop.
Save adityasuseno/048163849c29c17d851a8133e793f12b to your computer and use it in GitHub Desktop.
OOP Practice using Java
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