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.
What is the Government of India’s Revenue from Operations target for IREDA in FY 2025–26, as per its MoU with MNRE?
By which date is the Telangana government aiming to roll out the Bhu Bharati portal across the state?
When was the Ramsar Convention, focused on wetlands, originally signed?
Who assumed charge as the Director General of Defence Estates (DGDE) on 30 September 2025?
How many countries participated in the ARISE Cities Forum 2025 held in New Delhi?
Consider the following statements in regards to National Scheme of Incentives to Girls for Secondary Education (NSIGSE):
1. The Centrally Sponsor...
Which state recorded the highest Total Fertility Rate (TFR) in 2023?
Zerodha Asset Management Company (AMC) has received final approval from the market regulator SEBIÂ to commence a mutual fund (MF) business.The new entr...
What was the cumulative growth in the Index of Eight Core Industries (ICI) from April to October 2024?
As of July 1, 2025, how many years has the Goods and Services Tax (GST) been in operation?