I've written a Bike interface and implementing MountainBike class as below:
//interface package com.company; public interface Bike { void changeCadence(int newValue); void changeGear(int newValue); void speedUp(int increment); void applyBrakes(int decrement); } //implementing class package com.company; public class MyBike implements Bike{ int cadence = 0; int speed = 0; int gear = 1; // The compiler will now require that methods // changeCadence, changeGear, speedUp, and applyBrakes // all be implemented. Compilation will fail if those // methods are missing from this class. public void changeCadence(int newValue) { cadence = newValue; } public void changeGear(int newValue) { gear = newValue; } public void speedUp(int increment) { speed = speed + increment; } public void applyBrakes(int decrement) { speed = speed - decrement; } void printState(){ System.out.println("cadence:" + cadence + " speed:" + speed + " gear:" + gear); } public static void main(String[] args) { MyBike mBike = new MyBike(); mBike.changeCadence(20); mBike.changeGear(3); mBike.speedUp(20); mBike.applyBrakes(20); mBike.printState(); } } I understand that in this case I have to implement all the classes in interface within implementing class. However, if I use abstract class, I don't need to implement them all. If that's the case why not always use abstract class, in case I might implement only partially or maybe all classes from interface? Why do we need to use non-abstract class ?
MyBiketo abstract and see what happens.