Metode Pewarisan (inheritnace) code java.
Metode Pemarisan - Inheritance.
public class Main {
/**
* @param args
*/
public static
void main(String[] args) {
Mahasiswa
mhs = new Mahasiswa();
mhs.setNama("Erial");
mhs.setAlamat("Jl.
haji ridho");
mhs.setNim(113040213);
System.out.println("Nama
: "+ mhs.getNama());
System.out.println("Alamat
: "+ mhs.getAlamat());
System.out.println("Nim
: "+ mhs.getNim());
mhs.Bernafas();
}
}
|
public class Mahluk {
public void
Bernafas(){
System.out.println("Bernafas....");
}
}
|
public class Orang extends Mahluk {
public String
nama;
public String
alamat;
public void
setNama(String nama){
this.nama
= nama;
}
public void
setAlamat(String alamat){
this.alamat
= alamat;
}
public String
getNama(){
return
nama;
}
public String
getAlamat(){
return
alamat;
}
public Orang(){
System.out.println("orang
default java..");
}
}
|
public class Dosen extends Orang {
int nip;
public int
setNip(){
return
nip;
}
public void
getNip(int nip){
this.nip
= nip;
}
public Dosen(){
System.out.println("Dosen
dari java...");
}
public Dosen(int
nip){
System.out.println("Nip
: "+ nip);
}
}
|
public class Mahasiswa extends Orang{
public int nim;
public void
setNim(int nim){
this.nim
= nim;
}
public int
getNim(){
return
nim;
}
public
Mahasiswa(){
System.out.println("Mahasiswa
dari java...");
}
}
|
Posting Lebih Baru Posting Lama