Pewarisan Pada Java

Pewarisan pada Java menggunakan inputan user................!!!!
Semoga Bermanfaat........

import javax.swing.JOptionPane;

class hewan2 {
    private String NamaHewan;
    private String MakananHewan;
    private int BanyakKaki;
    private int nomer;

    private static int no = 0;

public hewan2 (String a, String b, int c){
    this.NamaHewan = a;
    this.MakananHewan = b;
    this.BanyakKaki = c;
    this.nomer = ++no;
}
public void lihatHewan(){
    System.out.println("Nomor :"+this.nomer);
    System.out.println("\tNama Hewan    :"+this.NamaHewan);
    System.out.println("\tMakanan       :"+this.MakananHewan);
    System.out.println("\tBanyak Kaki   :"+this.BanyakKaki);
}}

class hewanLanjutan extends hewan2 {
    private String habitatHewan;
    private String apakahtermasukhewanyangdiLindungi;

public hewanLanjutan (String a, String b, int c, String habitat, String apa ){
   super (a,b,c);
   this.habitatHewan = habitat;
   this.apakahtermasukhewanyangdiLindungi= apa;
}
    @Override
public void lihatHewan(){
    super.lihatHewan();
    System.out.println("\t\tHabitat Hewan   :" +this.habitatHewan);
    System.out.println("\t\tApakah Termasuk Hewan Yang Di Lindungi...????? :" +this.apakahtermasukhewanyangdiLindungi);
    }
}

class HewanApp{
    public static void main (String[] args){
                System.out.println("=========================================");
                System.out.println("========= *PEWARISAN PADA JAVA* =========");
                System.out.println("============aliefendy.blogspot.com==============");
                System.out.println("=========================================");

        String x1 = JOptionPane.showInputDialog(" Nama Hewan ");
        String x2 = JOptionPane.showInputDialog(" Makanan Hewan ");
        int x3 = Integer.parseInt(JOptionPane.showInputDialog(" Banyak Kaki "));
        String y1 = JOptionPane.showInputDialog(" Nama Hewan ");
        String y2 = JOptionPane.showInputDialog(" Makanan Hewan ");
        int y3 = Integer.parseInt(JOptionPane.showInputDialog(" Banyak Kaki "));
        String z1 = JOptionPane.showInputDialog(" Nama Hewan ");
        String z2 = JOptionPane.showInputDialog(" Makanan Hewan ");
        int z3 = Integer.parseInt(JOptionPane.showInputDialog(" Banyak Kaki "));
        String z4 = JOptionPane.showInputDialog(" Habitat Hewan ");
        String z5 = JOptionPane.showInputDialog(" Apakah Termasuk Hewan Yang Di Lindungi...????? ");
        hewan2 obyek1 = new hewan2 (x1,x2,x3);
        hewan2 obyek2 = new hewan2 (y1,y2,y3);
        hewanLanjutan obyek3 = new hewanLanjutan (z1,z2,z3,z4,z5);

        obyek1.lihatHewan();
        obyek2.lihatHewan();
        obyek3.lihatHewan();
    }
}

0 comments:

Posting Komentar