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 space tech firm will launch India’s first AI laboratory in space aboard PSLV C60?
What is the main purpose of the Government of India's decision to increase the authorized capital of the Food Corporation of India (FCI)?
What was the primary reason for the initial dispute over India’s import duties on IT products?
Who is the author of the book The Power of Humility : How Humble High Achievers Are Rewriting the Rules of Leadership?
Which ecosystem is the only one that does NOT thrive on solar energy?
Who was Leonardo Del Vecchio, who recently died?
PAN is compulsory if the amount exceeds,
Which of the following statements about REC's recognition and awards is/are correct?
1. REC Limited received the 'Innovative Technology Developme...
 Where in India the REC Limited organized ‘Bijli dance’ as a part of 'Azadi Ka Amrit Mahotsav?
KVIC opened the first of its kind Silk Proessing plant in _________.Â