0% found this document useful (0 votes)
71 views5 pages

Kelinci: Ciri dan Habitatnya

The document contains code for a program that defines classes for animals and their inheritance. It defines a parent hewan_inheritance class with attributes for skin color and number of legs. Child classes habitatdarat and kelinci extend this to add attributes for diet. The main method creates a kelinci object and calls methods to output its attributes. Additional classes hewan and panggil are defined to demonstrate polymorphism by creating and calling methods on a hewan object.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views5 pages

Kelinci: Ciri dan Habitatnya

The document contains code for a program that defines classes for animals and their inheritance. It defines a parent hewan_inheritance class with attributes for skin color and number of legs. Child classes habitatdarat and kelinci extend this to add attributes for diet. The main method creates a kelinci object and calls methods to output its attributes. Additional classes hewan and panggil are defined to demonstrate polymorphism by creating and calling methods on a hewan object.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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;

[Link] ("Warna Kulitnya : " +warnakulit);

void jumlahkaki (int jumlah)

jumlahkaki=jumlah;

[Link] ("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();

[Link] ("Kelinci memiliki ciri-ciri : ");

[Link]("Putih");

[Link](4);

[Link]("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;

[Link] ("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(){

[Link]("nama hewan ="+ nama);

[Link]("makanan ="+ makanan);

[Link]("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();


[Link]("kura-kura","sayuran dan buah-buahan", 4);

[Link]();

Output:

You might also like