Pages

Konsep PBO Pewarisan bag-1


//--------------------
//manusia.java
//--------------------
 package pewarisan;

public class manusia {

    public String nama, nim;

    public manusia(String n) {

        this.nama = n;
    }

    public String tampilkanNama() {

        return nama;
    }

    public void makan() {

        System.out.println("Nyam... nyam... nyam...");
    }

    public void kerja() {

        System.out.println("Kerja...kerjaaa...");
    }
}
/--------------------------------------------------------

//--------------------

//programmmer.java
//--------------------
package pewarisan;


public class programmmer extends manusia {


    public programmmer(String n) {
        super(n);
    }


    @Override
    public void kerja() {


        System.out.println("tak....tak..klik");
    }


    public void bersantai() {


        System.out.println("game over...you lose...");
    }
}


/--------------------------------------------------------

//--------------------
//tentara.java
//--------------------
package pewarisan;


public class tentara extends manusia {


    public String pangkat;


    public tentara(String n, String p) {
        super(n);
        this.pangkat = p;
    }


    public String tampilkanPangkat() {
        return pangkat;
    }


    public void kerja1() {
        System.out.println("dor..dor..dor...");
    }
}
/--------------------------------------------------------

//--------------------
//andi.java
//--------------------
  package pewarisan;


public class andi {


    public static void main(String args[]) {
        programmmer andi = new programmmer("andi");
        System.out.println("Nama" + andi.tampilkanNama());
        andi.makan();
        andi.kerja();
        andi.bersantai();
    }
}
/--------------------------------------------------------

//--------------------
//badu.java
//--------------------
  package pewarisan;


public class badu {


    public static void main(String args[]) {
        tentara badu = new tentara("badu", "kopral");
        System.out.println("nama" + badu.tampilkanNama());
        System.out.println("pangkat" + badu.tampilkanPangkat());
        badu.makan();
        badu.kerja1();
    }
}

0 comments:

Posting Komentar