Nama : Figuh Teguh Wibowo
Nim : 2012420130
>>Super class
public class hewan {
protected
String nama;
public
hewan(String nama) {
this.nama =
nama;
}
public void
tampil(){
}
}
>>sub class
>>sub class
package hewan;
public class monyet extends hewan{
public
monyet(String nama){
super(nama);
}
@Override
public void tampil(){
System.out.println("nama = "+super.nama);
}
}
>>Sub class
package hewan;
/**
*
* @figuhae
*/
public class asu extends hewan {
public asu(String
nama){
super(nama);
}
@Override
public void tampil(){
System.out.println("nama = "+super.nama);
}}
Sub class
package hewan;
/**
*
* @@figuhae
*/
public class ikan extends hewan {
public ikan
(String nama){
super(nama);
}
@Override
public void
tampil(){
System.out.println("nama = "+super.nama);
}
}
Method main
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package hewan;
/**
*
* @figuhae
*/
public class Main {
/**
* @param args the
command line arguments
*/
public static void
main(String[] args) {
// TODO code
application logic here
//h1 untuk
hewan
hewan h1;
ikan ikan=new
ikan("ikan koi");
monyet
monyet=new monyet("kera putih");
asu asu = new
asu ("anjing haci");
h1=ikan;
h1.tampil();
h1=monyet;
h1.tampil();
h1=asu;
h1.tampil();
}
}
Posted by 23.20 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar