public class cMenu {
private String nama;
protected double harga;
cMenu(){
System.out.println("Default constructor...");
}
cMenu(String n, double h){
nama=n; harga=h;
System.out.println("Object menu dibuat...");
public void setNama(String n){
nama=n;
}
public void setHarga(double h){
harga=h;
}
public String getNama(){
return nama;
}
public double getHarga(){
return harga;
}
public void info(){
System.out.println("Induk : "+nama+"\t"+harga);
}
}
public class cMakanan extends cMenu{
cMakanan(){
System.out.println("Default constructor...");
}
cMakanan(String n, double h){
super(n,h);
System.out.println("Object makanan dibuat...");
}
@Override
public void info(){
System.out.println("Info di Anak : ");
super.info();
}
}
public class cMinuman extends cMenu {
cMinuman(String n, double h){
super(n,h);
System.out.println("Object minuman dibuat...");
}
}
public class cSeaFood extends cMakanan{
//kosong
}
public class appWarung {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
cMakanan mkn = new cMakanan("Soto",20000);
System.out.println("Nama makanan : "+mkn.getNama());
System.out.println("Harga : "+mkn.getHarga());
mkn.harga=15000;
System.out.println("Nama makanan : "+mkn.getNama());
System.out.println("Harga : "+mkn.getHarga());
mkn.info();
cMinuman mnm = new cMinuman("Es Jeruk",3000);
System.out.println("Nama Minuman : "+mnm.getNama());
System.out.println("Harga : "+mnm.getHarga());
cSeaFood sf = new cSeaFood();
sf.setNama("Cumi Bakar");
sf.setHarga(25000);
System.out.println("Nama : "+sf.getNama());
System.out.println("Harga : "+sf.getHarga());
System.out.println("Coba pewarisan...");
}
}
No comments:
Post a Comment