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(); }}Solution
In the provided Java code, the Car class has a composition relationship with the Engine class, meaning that an Engine instance is created within the Car class. When the start method of the Car class is invoked, it calls the start method of the Engine instance, which outputs "Engine started." Therefore, the output of the code is Engine started. Why Other Options Are Wrong: B) Car started: This option is incorrect as there is no start method in the Car class that prints Car started; it delegates to the Engine. C) No output: This option is incorrect because the code clearly produces an output when the start method is called. D) Compilation error: This option is incorrect as the code is syntactically correct and will compile successfully. E) Runtime error: This option is incorrect because there are no conditions in the code that would lead to a runtime error; it executes as intended.
Open market operations, one of the monetary measures taken by RBI is:
What is the key feature of the SCORE system developed by SAMEER?
India achieved the presidency of which international administrative body in the month of June 2025?
Who had won the Polish presidential election on 1 June 2025?
Where is the Head Quarter of Asian Clearing Union (ACU)?
Which country signed a deal to supply 90 tons of uranium to India for its nuclear power plants in 2025?
Who won the Best Actor in a Leading Role award at the 97th Academy Awards (Oscars) 2025?
Which of the following social media giant has recently launched a parent controlled messenger app
Who was named Director of the Prime Minister’s Museum & Library in the June 2025?
Recently Goods and Services Tax network has been included to the account aggregator (AA) network as a financial information provider (FIP) to facilitate...