Tuesday, October 1, 2013

contoh class fungsi kumaidi

buat java aplikasi dengan nama Latihan
codenya sebagai berikut

public class Latihan {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        mobil lancer = new mobil();
       lancer.merk = "mitsubishi";
       lancer.jenis = "sport";

       mobil rush = new mobil();
       rush.merk = "toyota";
       rush.jenis = "suv";

       mobil vwcombi = new mobil();
       vwcombi.merk = "volkswagen";
       vwcombi.jenis = "classic";
       
       
        motor monster = new motor();
        monster.merk = "ducati";
        monster.jenis = "sport";

        motor jupiterz = new motor();
        jupiterz.merk = "yamaha";
        jupiterz.jenis = "bebek";

        motor supercup = new motor();
        supercup.merk = "honda";
        supercup.jenis = "classic";
        
        System.out.println(lancer.merk);
        System.out.println(lancer.jenis);
        System.out.println(monster.merk);
        System.out.println(rush.merk);
               
    }
}

buat class mobil 
public class mobil {
    String merk;
    String jenis;
    
}

buat class motor
public class motor {
    String merk;
    String jenis;
}

No comments:

Post a Comment