Pages

Konsep PBO Pengkapsulan Bag-1


//--------------------
//mahasiswa.java
//--------------------
package pengkapsulan;

public class mahasiswa {

    private int nrp;
    private String nama;

    public mahasiswa(int i, String n) {
        this.nrp = i;
        this.nama = n;
    }

    public void setNRP(int nrp) {
        this.nrp = nrp;
    }

    public int getNRP() {
        return nrp;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public String getNama() {
        return nama;
    }
}
//-------------------------------------------------------- 


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

//tesMahasiswa.java
//--------------------
package pengkapsulan;

public class tesMahasiswa {

    public static void main(String args[]) {
        int nomer;
        String nm;
        mahasiswa m = new mahasiswa(123, "shinta");
        System.out.println(m.getNRP());
        System.out.println(m.getNama());
        m.setNama("cheen");
        m.setNRP(333);
        System.out.println(m.getNRP());
        System.out.println(m.getNama());
    }
}
 
//-------------------------------------------------------- 


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

//output
//--------------------
  
123
shinta
333
cheen

0 comments:

Posting Komentar