Social Icons

Monday, 20 January 2014

program java Encapsulation, Inheritance ,polymorphisme



OOP (TEORI DAN PRAKTEK)

NAMA  : ANDI SULAEMAN
NIM       :A3.1100004
PROD    :SISTEM INFORMASI


untuk info lebih lanjut hubungi: aku di inbox fb klik aja
1.       Encapsulation(pembungkusan) jadipadakelasenkapsulasisayamendeklarasikan variable bertype string kedalam Access Modifier Public
2.       Inheritance (pewari ) sifat-sifatdarisuatukelasditurunkankekelas lain
3.      PolymorphismeSifathierarkisuatu inheritance pada class diagram adalahsemakinkeatassemakin generic.

1.       Encapsulation
class User {
                private String nama;
                private String alamat;
                privateint id;
                public void setUser ( String namaM, String alamatM , intidM) {
                                nama = namaM;
                                alamat = alamatM;
                                id = idM;
                }
                public String getUserNama () {
                                returnnama;
                }
                publicintgetUserId () {
                                return id;
                }
                public String getUserAlamat() {
                                returnalamat;
                }
public static void main (String[] args) {
                User Biodata = new User();
Biodata.setUser("ANDI SULAEMAN","SUMEDANG",1234);
                System.out.println("ID = " + Biodata.getUserId());
System.out.println("Nama  = "+ Biodata.getUserNama());
System.out.println("Alamat  = "+ Biodata.getUserAlamat());

            }
}


                               
2.       Inheritance


class User {
                private String nama;
                private String alamat;
                privateint id;
                public void setUser ( String namaM, String alamatM , intidM) {
                                nama = namaM;
                                alamat = alamatM;
                                id = idM;
                }
public String getUserNama () {
                                returnnama;
                }
publicintgetUserId () {
                                return id;
                }
                public String getUserAlamat() {
                                returnalamat;
                }
                public static void main (String[] args) {
                User Biodata = new User();
                mahasiswamhs = new mahasiswa();
Biodata.setUser("andi","sumedang",1234);
                mhs.setJurusan("SistemInformasi");
System.out.println("ID = " + Biodata.getUserId());
System.out.println("Nama  = "+ Biodata.getUserNama());
System.out.println("Alamat  = "+ Biodata.getUserAlamat());
                System.out.println("Jurusan = "+ mhs.getJurusan());

            }
                }
classmahasiswa extends User {
private String jurusan;
public void setJurusan(String jurusanM) {
urusan = jurusanM;
                }
                public String getJurusan() {
                                returnjurusan;
                }
}
Tampilanpadacmd:
 

3.       Polymorphisme
abstract class User {
                protected String nama;
                protected String alamat;
                protected String jurusan;
                protectedint id;
                public String getUserNama () {
                                returnnama;
                }
                publicintgetUserId () {
                                return id;
                }
                public String getUserAlamat() {
                                returnalamat;
                }
                public String getUserJurusan() {
                                returnjurusan;
                }
               
}

classmahasiswa extends User {
publicmahasiswa ( String nama, String alamat , int id , String jurusan) {
                                this.nama = nama;
                                this.alamat = alamat;
                                this.id = id;
                                this.jurusan = jurusan;
                }
public String getUserNama () {
                                returnnama;
                }
                publicintgetUserId () {
                                return id;
                }
public String getUserAlamat() {
                                returnalamat;
                }
                public String getUserJurusan() {
                                returnjurusan;
                }

               
}

classcetak{
                public static void cetakMahasiswa(User ctk) {
                                System.out.println("ID : " + ctk.getUserId());
                                System.out.println("Nama : " + ctk.getUserNama());
                                System.out.println("Alamat : "+ ctk.getUserAlamat());
                                System.out.println("jurusan : "+ctk.getUserJurusan());
                }
                public static void main(String args[]) {
mahasiswa mhs1 = new mahasiswa("abdulrohman", "Sumedang" , 15456 , "sisteminformasi");
mahasiswa mhs2 = new mahasiswa("AndiSulaeman", "Sumedang" , 1234, "SistemInformasi");
mahasiswa mhs3 = new mahasiswa("efrilian", "Sumedang" , 27585 , "SistemInformasi");
                cetakMahasiswa(mhs1);
                cetakMahasiswa(mhs2);
cetakMahasiswa(mhs3);
               
                }
}




Tampilanpada CMD:

 

NOTE: JAVA sangatlah sensitive dalam karakter penulisan hendakalah sangat teliti
Kesimpulandarianalisatsb:


No comments:

Post a Comment

 

Sample text

lan

iklan

Belum ada iklan gan

Sample Text