public void injakPedalGas();
public void injakRem(){
System.out.println(“Mobil berhenti!”);
}
}
public class Kijang extends Mobil{
public void injakPedalGas(){
System.out.println("Mobil Melaju dengan kecepatan 80 Km/jam...");
}
}
public class BMW extends Mobil {
public void injakPedalGas(){
System.out.println("Mobil Melaju dengan kecepatan 100 Km/jam...");
}
}
>> class for running
public class TestMobil {
public static void main(String[] args){
Mobil mobil = new Mobil(){
public void injakPedalGas(){
System.out.println("Mobil berjalan...");
}
};
Kijang kijang = new Kijang();
Escudo escudo = new Escudo();
BMW bmw = new BMW();
mobil.injakPedalGas();
mobil = kijang;
mobil.injakPedalGas();
mobil = escudo;
mobil.injakPedalGas();
mobil = bmw;
mobil.injakPedalGas();
}
}
No comments:
Post a Comment