Abstract method is used for inheritance, when Object B
IS Object A
. Interface is used when Object B
HAS Object A
. For example, BMW is a CAR, but CAR is not ENGINE, CAR has ENGINE. But other than that, there are only few technical nuances between them. The logic here is most important.
EDIT: Due to popular demand, here is my example:
interface Engine {
horsePower(int a);
torque(int a);
volume(int a);
//...
}
Car
abstract class Car implements Engine {
//implement interface methods
public abstract accelerate(int howMuch, int horsePower);
public abstract brake(int howMuch);
public abstract turn(int degreesOfRotation);
//..
}
And the BMW
public class BMW extends Car {
private final String carMake = "BMW";
private String carModel;
// implement abstract methods of Car
public void setModel(String s){
carModel = s;
//and so on
}