public class cBarang {
private String kode;
private String nama;
private double harga;
cBarang(){
kode=""; nama=""; harga=0;
System.out.println("Object barang dibuat...");
}
cBarang(String k, String n, double h){
kode=k; nama=n; harga=h;
System.out.println("Induk...");
System.out.println("Object barang dibuat...");
public String getNama(){
return nama;
}
public String getKode(){
return kode;
}
public double getHarga(){
return harga;
}
public void info(){
System.out.println("Info di class induk");
System.out.println(kode+"\t"+nama+"\t"+harga);
}
}
public class cBaju extends cBarang {
private String kain;
cBaju(String k, String n, double h, String ka){
super(k,n,h); //jalankan constructor class induk
kain=ka;
System.out.println("Object baju dibuat...");
}
public String getKain(){
return kain;
}
@Override
public void info(){
super.info();
System.out.println("Info di class anak...");
}
}
public class cSeragam extends cBaju{
cSeragam(String k, String n, double h, String b){
super(k,n,h,b); //jalankan constructor class induk
System.out.println("Object seragam dibuat...");
}
}
public class cSepatu extends cBarang{
private String ukuran;
cSepatu(String k, String n, double h, String u){
super(k,n,h); //jalankan constructor class induk
ukuran=u;
System.out.println("Object sepatu dibuat...");
}
public String getUkuran(){
return ukuran;
}
}
public class appToko {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
cSeragam srg = new cSeragam("123","Seragam SD",100000,"Katun");
srg.info();
System.out.println("Kode = "+srg.getKode());
System.out.println("Nama = "+srg.getNama());
System.out.println("Harga = "+srg.getHarga());
System.out.println("Bahan = "+srg.getKain());
cSepatu spt = new cSepatu("456","Sepatu Sport",300000,"40");
spt.info();
System.out.println("Kode = "+spt.getKode());
System.out.println("Nama = "+spt.getNama());
System.out.println("Harga = "+spt.getHarga());
System.out.println("Ukuran = "+spt.getUkuran());
System.out.println("Coba pewarisan...");
...
}
No comments:
Post a Comment