Objek yang digunakan pada pembuatan class ini yaitu Mouse. Yuk disimak.
Mouse.java
package mouse;
public class Mouse {
String warna;
String merk;
String seri;
private String Status_klikKiri;
private String Status_klikKanan;
private String scroll;
public Mouse(){
this.warna=("Hitam");
this.merk=("Logitech");
this.seri=("LGTCH101");
this.Status_klikKiri=("none");
this.Status_klikKanan=("none");
this.scroll=("none");
}
public Mouse(String warna, String merk, String seri, String
Status_klikKiri,
String Status_klikKanan, String
scroll){
this.warna=warna;
this.merk=merk;
this.seri=seri;
this.Status_klikKiri=Status_klikKiri;
this.Status_klikKanan=Status_klikKanan;
this.scroll=scroll;
}
public void set_warna(String warna){
this.warna=warna;
}
public String get_warna(){
return warna;
}
public void set_merk(String merk){
this.merk=merk;
}
public String get_merk(){
return merk;
}
public void set_seri(String seri){
this.seri=seri;
}
public String get_seri(){
return seri;
}
public void set_Status_klikKiri(String Status_klikKiri){
this.Status_klikKiri=Status_klikKiri;
}
public String get_Status_klikKiri(){
return Status_klikKiri;
}
public void set_Status_klikKanan(String Status_klikKanan){
this.Status_klikKanan=Status_klikKanan;
}
public String get_Status_klikKanan(){
return Status_klikKanan;
}
public void set_scroll(String scroll){
this.scroll=scroll;
}
public String get_scroll(){
return scroll;
}
}Nah kemudian Class mouse tersebut memiliki sub class yang saya beri nama MouseKabel.
MouseKabel.java
package mouse;
public class MouseKabel extends
Mouse{
private String tipe_mouse;
private Mouse mk1;
public MouseKabel(){
this.tipe_mouse=("Kabel");
}
public MouseKabel(String warna, String merk, String seri,
String Status_klikKiri, String
Status_klikKanan, String scroll) {
super(warna, merk, seri,
Status_klikKiri, Status_klikKanan,
scroll);
}
public MouseKabel(String tipe_mouse){
this.tipe_mouse=tipe_mouse;
}
public Mouse get_mk1(){
return mk1;
}
public String get_tipe_mouse(){
return tipe_mouse;
}
} Agar class tersebut dapat digunakan, maka kita terlebih dahulu membuat program utamanya.
Main.java
package mouse;
public class main {
public static void main(String[] args) {
Mouse m = new
Mouse("Silver","Microsoft","MS2103","Aktif","none","none");
MouseKabel m1 = new MouseKabel();
System.out.println("Warna :
"+m.get_warna());
System.out.println("Merk :
"+m.get_merk());
System.out.println("Seri :
"+m.get_seri());
System.out.println("Klik Kiri :
"+m.get_Status_klikKiri());
System.out.println("Klik Kanan :
"+m.get_Status_klikKanan());
System.out.println("Scroll :
"+m.get_scroll());
System.out.println("\n");
System.out.println("Warna :
"+m1.get_warna());
System.out.println("Tipe Mouse :
"+m1.get_tipe_mouse());
System.out.println("Merk :
"+m1.get_merk());
System.out.println("Seri :
"+m1.get_seri());
System.out.println("Klik Kiri :
"+m1.get_Status_klikKiri());
System.out.println("Klik Kanan :
"+m1.get_Status_klikKanan());
System.out.println("Scroll :
"+m1.get_scroll());
}
} Semoga artikel ini dapat membantu.
Atau yang ingin filenya bisa didownload : disini
0 komentar:
Posting Komentar