BlackBoY_

ConstWithParameter

May 25th, 2021
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class BINATANG {
  2.     String nama,jenis,habitat;
  3.    
  4.     BINATANG(String nm, String jns, String hbtt){
  5.         nama = nm;
  6.         jenis = jns;
  7.         habitat = hbtt;
  8.        
  9.         System.out.println("Nama Binatang : "+nama);
  10.         System.out.println("Jenis         : "+jenis);
  11.         System.out.println("Habitat       : "+habitat);
  12.     }
  13.     void suara(){
  14.         switch (nama){
  15.             case "Anjing" : System.out.println("pinjem duit dong besok gw ganti"); break;
  16.             case "Kucing" : System.out.println("Aih malunya aku");break;
  17.             case "Buaya"  : System.out.println("Km sudah punya cowok kah?");break;
  18.             default       : System.out.println("gada suara");
  19.         }
  20.     }
  21.    
  22.     public static void main(String[] args) {
  23.         BINATANG binatang1 = new BINATANG("Anjing", "Humanis Dog", "Kompleks");
  24.         binatang1.suara();
  25.         System.out.println("");
  26.         BINATANG binatang2 = new BINATANG("Kucing", "Teaser Cat", "Warung");
  27.         binatang2.suara();
  28.         System.out.println("");
  29.         BINATANG binatang3 = new BINATANG("Buaya", "Player", "Hati");
  30.         binatang3.suara();
  31.        
  32. }
  33. }
Add Comment
Please, Sign In to add comment