0% found this document useful (0 votes)
48 views

Program Interface

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
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Program Interface

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
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;

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:

You might also like