interface IntLampu {
public static final int KEADAAN_HIDUP = 1;
public static final int KEADAAN_MATI = 0;
public abstract void hidupkan();
public abstract void matikan();
} // Akhir interface
class Lampu implements IntLampu{
private int statusLampu = 0;
public void hidupkan() {
if (this.statusLampu == KEADAAN_MATI){
this.statusLampu = KEADAAN_HIDUP;
System.out.println("Lampu hidup");
}
else {
System.out.println("Lampu sudah hidup");
}
}
public void matikan() {
if (this.statusLampu == KEADAAN_HIDUP){
this.statusLampu = KEADAAN_MATI;
System.out.println("Lampu mati");
}
else {
System.out.println("Lampu sudah mati");
}
}
} // Akhir kelas
public class TesInterface {
public static void main(String[] args) {
Lampu lampuKamar = new Lampu();
lampuKamar.hidupkan();
lampuKamar.hidupkan();
lampuKamar.matikan();
lampuKamar.matikan();
}
}
Post a Comment