oop - Quelle est la différence entre une interface et une classe abstraite

Mots clés : oopinterfaceabstract-classoop

meilleur 1 Réponses oop - Quelle est la différence entre une interface et une classe abstraite

vote vote

90

// I say all motor vehicles should look like this: interface MotorVehicle {     void run();      int getFuel(); }  // My team mate complies and writes vehicle looking that way class Car implements MotorVehicle {      int fuel;      void run()     {         print("Wrroooooooom");     }       int getFuel()     {         return this.fuel;     } } 
// I say all motor vehicles should look like this: abstract class MotorVehicle {      int fuel;      // They ALL have fuel, so lets implement this for everybody.     int getFuel()     {          return this.fuel;     }      // That can be very different, force them to provide their     // own implementation.     abstract void run(); }  // My teammate complies and writes vehicle looking that way class Car extends MotorVehicle {     void run()     {         print("Wrroooooooom");     } } 

Questions similaires