Tips Blog, Tips and Trik, Software, Belajar Program

Program Membuat Super Class Dan Sub Class


SuperClass : Person

class Person{
private String Nama;
private String Alamat;
private int Umur;

public Person(){

}

public Person(String Nama, String Alamat, int Umur){
this.Nama = Nama;
this.Alamat = Alamat;
this.Umur = Umur;
}

public String getNama(){
return Nama;
}

public String getAlamat(){
return Alamat;
}

public int getUmur(){
return Umur;
}

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

public void setAlamat(String Alamat){
this.Alamat = Alamat;
}

public void setUmur(int Umur){
this.Umur = Umur;
}

public void infoPerson() {
System.out.println("\nInfo Person");
System.out.println("Nama\t\t: " + getNama());
System.out.println("Alamat\t\t: " + getAlamat());
System.out.println("Umur\t\t: " + getUmur());
}
}

SubClass : Dosen

class Dosen extends Person{
private String idDosen;

public Dosen(){
}

public Dosen(String Nama, String Alamat, int Umur, String idDosen){
super(Nama, Alamat, Umur);
this.idDosen = idDosen;
}

public String getIdDosen(){
return idDosen;
}

public void setIdDosen(String idDosen){
this.idDosen = idDosen;
}

public void infoDosen(){
System.out.println("\nInfo Dosen");
System.out.println("idDosen\t\t: " + getIdDosen());
System.out.println("Nama\t\t: " + getNama());
System.out.println("Alamat\t\t: " + getAlamat());
System.out.println("Umur\t\t: " + getUmur());
}


}

SubClass : Mahasiswa

class Mahasiswa extends Person{
private String NIM;

public Mahasiswa(){
}

public Mahasiswa(String Nama, String Alamat, int Umur, String NIM){
super(Nama, Alamat, Umur);
this.NIM = NIM;
}

public String getNIM(){
return NIM;
}

public void setNIM(String NIM){
this.NIM = NIM;
}

public void infoMahasiswa(){
System.out.println("\nInfo Mahasiswa");
System.out.println("NIM\t\t: " + getNIM());
System.out.println("Nama\t\t: " + getNama());
System.out.println("Alamat\t\t: " + getAlamat());
System.out.println("Umur\t\t: " + getUmur());
}


}

Class Method Main

class tampil{
public static void main(String[]asdasd){
Person a = new Person("di isi nama sesuai compilan","Korea",7777);
a.infoPerson();

Dosen b = new Dosen("Cahayani","Jogja",Jepang,"8899");
b.infoDosen();

Mahasiswa c = new Mahasiswa("Dina","Indonesia",22,"14.12.0004");
c.infoMahasiswa();
System.out.println("-----------------------------------");
}
}







Share :

Facebook Twitter Google+
0 Komentar untuk "Program Membuat Super Class Dan Sub Class"

Back To Top