Kamis, 26 April 2018

Polymorpshim java

kuis :
buat 3 kelas : honda , yamaha , suzuki
inheritance merk motor , lakukan polymorpshim
merek motor , jenis motor, warna motor, jenis bahan bakar , serta memiliki void motor dengan 3 tampilan .

1.honda :
merek : beat
jenis : matic
warna : hitam
bahan bakar : premium

2.yamaha
merek : mio
jenis : matic
warna : putih
bahan bakar : premium

3.suzuki
merek : nex
jenis : matic
warna : merah
bahan bakar : premium

jawab: 

/*
 * 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 TASK2;

/**
 *
 * @author pemakanwortel
 */
class Honda{
    public void Motor(){
        System.out.println("`HONDA");
        System.out.println("MEREK MOTOR : HONDA");
        System.out.println("JENIS MOTOR : MATIC");
        System.out.println("WARNA MOTOR : HITAM");
        System.out.println("BAHAN BAKAR : PREMIUM");
    }
}
class Yamaha extends Honda{
    public void Motor(){
        System.out.println("`YAMAHA");
        System.out.println("MEREK MOTOR : MIO");
        System.out.println("JENIS MOTOR : MATIC");
        System.out.println("WARNA MOTOR : PUTIH");
        System.out.println("BAHAN BAKAR : PREMIUM");
    }
}
class Suzuki extends Honda{
    public void Motor(){
        System.out.println("`SUZUKI");
        System.out.println("MEREK MOTOR : NEXT");
        System.out.println("JENIS MOTOR : MATIC");
        System.out.println("WARNA MOTOR : MERAH");
        System.out.println("BAHAN BAKAR : PREMIUM");
    }
}

public class Polymorphism {
    public static void main(String[] args) {
        Honda HONDA = new Honda();
        Yamaha YAMAHA = new Yamaha();
        Suzuki SUZUKI = new Suzuki();
        HONDA.Motor();
        HONDA = YAMAHA;
        HONDA.Motor();
        HONDA = SUZUKI;
        HONDA.Motor();
       
    }
}

output :
`HONDA
MEREK MOTOR : HONDA
JENIS MOTOR : MATIC
WARNA MOTOR : HITAM
BAHAN BAKAR : PREMIUM
`YAMAHA
MEREK MOTOR : MIO
JENIS MOTOR : MATIC
WARNA MOTOR : PUTIH
BAHAN BAKAR : PREMIUM
`SUZUKI
MEREK MOTOR : NEXT
JENIS MOTOR : MATIC
WARNA MOTOR : MERAH
BAHAN BAKAR : PREMIUM

Tidak ada komentar:

Posting Komentar

komentar nya yang bijak ya ..