public class komputerconstructor {
public String Nama;
public String ret;
public Boolean on = false;
public int volume = 0;
public String os;
//constructor overloading
public komputerconstructor(String os) {
this.os = os;
}
public komputerconstructor(String Nama,boolean on) {
this.Nama = Nama;
}
public komputerconstructor(int volume ) {
this.volume = volume;
this.on = on;
}
//Method overloading
public void print_komputer(String Temp) {
System.out.println("\nObjek Komputer " + Nama + " Berhasil Di buat");
}
public void print_komputer(String os, boolean on) {
System.out.println("os Komputer adalah " + os + " Windows ");
}
public void print_komputer(int volume) {
if (on == true) {
ret = "Komputer Nyala";
} else {
ret = "Komputer Mati";
}
if (volume > 0) {
ret += " Dengan Volume " + volume;
}
System.out.println(ret);
}
//
public String getNama() {
return Nama;
}
public void setNama(String Temp) {
Nama = Temp;
}
public String getos() {
return os;
}
public void setfos(String os ) {
this.os = os;
}
public int getvolume() {
return volume;
}
public void setvolume(int volume) {
this.volume = volume;
}
public boolean geton() {
return on;
}
public void seton(boolean on) {
this.on = on;
}
public static void main(String[] args) {
//Constructor overloading
komputerconstructor a = new komputerconstructor("ganang");
komputerconstructor x = new komputerconstructor(100);
komputerconstructor y = new komputerconstructor("Windows", true);
//method overloading
a.print_komputer(a.getNama());
x.print_komputer(y.getvolume());
y.print_komputer(x.getos(), y.geton());
}
}
Posted by 06.49 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar