Pages

Konsep PBO Pewarisan bag-2


//--------------------
//mahasiswa.java
//--------------------
package pewarisan;

public class mahasiswa {

    public String nama, nim;

    public mahasiswa(String n, String nim) {
        this.nama = n;
        this.nim = nim;
    }

    public String tampilkanNama() {
        return nama;
    }

    public String tampilkanNim() {
        return nim;
    }

    public void belajar() {
        System.out.println("Sinau... Sinau...Sinau...");
    }

    public void olahRaga() {
        System.out.println("...kerjaaa...");
    }

    public void makan() {
        System.out.println("Nyam....Nyam....");
    }

    public void minum() {
        System.out.println("Glek...Glek...");
    }
}
 



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

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

//pecintaalam.java
//--------------------
package pewarisan;

public class pecintaalam extends mahasiswa {

    public String nip;

    public pecintaalam(String n, String m, String p) {
        super(n, m);
        this.nip = p;
    }

    public String nipnya() {
        return nip;
    }

    public void arungjeram() {
        System.out.println("ok wes ..ayo budhal arung jeram");
    }

    public void mendakigunung() {
        System.out.println("loh..kate mungga gunung ndi???");
    }
}
 
//-------------------------------------------------------- 

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

//shinta.java
//--------------------
  package pewarisan;

public class shinta {

    public static void main(String args[]) {
        pecintaalam shinta = new pecintaalam("shinta", "08650153", "6167");

        System.out.println("nama" + shinta.tampilkanNama());
        System.out.println("nim" + shinta.tampilkanNim());
        System.out.println("nip" + shinta.nipnya());
        shinta.mendakigunung();
        shinta.nipnya();
    }
}



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

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

//output
//--------------------


namashinta
nim08650153
nip6167
loh..kate mungga gunung ndi???

0 comments:

Posting Komentar