Last active
August 29, 2015 13:57
-
-
Save Hoolean/9864950 to your computer and use it in GitHub Desktop.
Interfaces and Abstract Classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Drivable | |
{ | |
public void drive(); | |
} | |
public abstract Plane implements Drivable | |
{ | |
@Override | |
public void drive() | |
{ | |
// drive in a plane sort of way | |
} | |
} | |
public abstract Car implements Drivable | |
{ | |
boolean fuelEmpty = false; | |
@Override | |
public void drive() | |
{ | |
useFuel(); | |
goForward(); | |
} | |
public void goForward() | |
{ | |
/* use wheels and stuff */ | |
} | |
public boolean isFuelEmpty() | |
{ | |
return fuelEmpty; | |
} | |
public boolean setFuelEmpty(boolean empty) | |
{ | |
fuelEmpty = empty; | |
} | |
public abstract void useFuel(); | |
} | |
public class DiesalCar extends Car | |
{ | |
@Override | |
public void useFuel() | |
{ | |
/* use fuel in a diesal way */ | |
setEmpty(true); | |
} | |
} | |
public class PetrolCar extends Car | |
{ | |
@Override | |
public void useFuel() | |
{ | |
/* use fuel in a diesal way */ | |
setEmpty(true); | |
} | |
} | |
public class SolarPanelCar extends Car | |
{ | |
@Override | |
public void useFuel() | |
{ | |
/* use solar panel */ | |
} | |
} | |
// as for usage of implements | |
public void PhysicsHandler | |
{ | |
public static driveVehicle(Drivable drivableVehicle) | |
{ | |
drivableVehicle.drive(); | |
} | |
public static driveCar(Car car) | |
{ | |
car.drive(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment