0

When you extend an abstract class which implements an interface, does the child class change it's behavior if you write that it also implements the same interface that the abstract class does? Or is it just a readability question if you do it or not?

Interface example:

public interface Car
{
    public String startEngine();
}

Abstract class example:

public abstract class AbstractCar implements Car
{
    protected String engineStartUpSound;
}

Child class example #1:

public class Volvo extends AbstractCar <---- here
{
    public Volvo()
    { engineStartUpSound = "vroom!"; }

    @Override
    public final String startEngine()
    { return super.engineStartUpSound; }
}

Child class example #2:

public class Volvo extends AbstractCar implements Car <---- here
{
    public Volvo()
    { engineStartUpSound = "vroom!"; }

    @Override
    public final String startEngine()
    { return super.engineStartUpSound; }
}
kartibrown
  • 52
  • 6

0 Answers0