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.
Which of the following Key Employment Indicators is/are incorrectly matched?
Which of the following is/are the determinants of MSP?
(i) Cost of Production
(ii) demand and supply
(iii) price trend
...How much amount has been invested by World Bank since the implementation of Pradhan Mantri Gram Sadak Yojna (PMGSY)?
What is the name of the NRLM Mobile App to give facilities of e-Commerce?
Ministry of Agriculture and Farmers’ Welfare has approved the continuation of the Integrated Scheme for Agricultural Marketing (ISAM) scheme up to ___...
Which of the following is NOT a feature of the Targeted Public Distribution System (TPDS) under the NFSA?
Which of the following is the objectives of PM PRANAM scheme?
When was the AMRUT Scheme launched?
How many additional rural and urban households will be provided assistance for house construction under the Pradhan Mantri Awas Yojana (PMAY)?
Which of the following is the theme for recently conducted Economic Times Global Business Summit 2023?