Sunteți pe pagina 1din 5

program Interface

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package inheritance;

/**

* @author Gi0

*/

public class hewan_inheritance

String warnakulit;

int jumlahkaki;

void warnakulit (String warna)

warnakulit=warna;

System.out.println ("Warna Kulitnya : " +warnakulit);

void jumlahkaki (int jumlah)

jumlahkaki=jumlah;

System.out.println ("Jumlah Kakinya : " +jumlahkaki);

}
/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package inheritance;

/**

* @author Gi0

*/

public class kelinci

public static void main (String[] args)

habitatdarat kelinci = new habitatdarat();

System.out.println ("Kelinci memiliki ciri-ciri : ");

kelinci.warnakulit("Putih");

kelinci.jumlahkaki(4);

kelinci.pemakan("Tumbuhan");

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/
package inheritance;

/**

* @author Gi0

*/

public class habitatdarat extends hewan_inheritance

String makan;

public void pemakan (String makanan)

makan=makanan;

System.out.println ("Makanannya : " +makan);

Polymorphisme

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author Gi0

*/

public class hewan {

int kaki;
String nama, makanan;

void inputData(String x,String y, int z){

kaki = z ;

nama =x ;

makanan = y ;

void cetak(){

System.out.println("nama hewan ="+ nama);

System.out.println("makanan ="+ makanan);

System.out.println("jumlah kaki ="+ kaki);

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author Gi0

*/

public class panggil {

public static void main (String[]args){

hewan r= new hewan();


r.inputData("kura-kura","sayuran dan buah-buahan", 4);

r.cetak();

Output:

S-ar putea să vă placă și