Question

What will be the output of the following code snippet demonstrating composition in Java? class Engine { void start() {         System.out.println("Engine started.");     }} class Car {     private Engine engine;     Car() {         engine = new Engine(); // Composition     }     void start() {         engine.start();     }} public class Test {     public static void main(String[] args) {         Car car = new Car();         car.start();     }}

A Engine started.
B Car started.
C No output.
D Compilation error.
E Runtime error.
Practice Next

Relevant for Exams:

Hey! Ask a query