interface InternalCombustionEngine { /* ... */ }
abstract class FourStrokeEngine implements InternalCombustionEngine { /* ... */ }
class GeneralMotorsLS3 extends FourStrokeEngine { /* ... */ }
class ChevroletCorvette implements InternalCombustionEngine {
FourStrokeEngine engine;
/*
* Receive abstract class so that changes in it can transparently
* update all classes that extend the abstract class.
*/
void setEngine(FourStrokeEngine e) { engine = e; }
// Return interface rather than concrete class to allow widest possible use
InternalCombustionEngine getEngine() { return engine; }
public static int main(String[] args) {
var corvette = new ChevroletCorvette();
corvette.setEngine(new GeneralMotorsLS3());
return 0;
}
}