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.
If (5sinx - cosx) = 2√2sinx, then find the value of 'tanx'
From the top of a building, the angle of depression of two cars on a straight road are 30° and 60° respectively. If the height of the building is 120 ...
If cos 2x = 1/2, then the value of x:
If Sin θ + Cos θ = √2 Cos(90 - θ ), then find the value of Cot θ ?
...If tan 2 α = 1 + 2tan 2 β, then find the value of √2cos α – cos β = ?
- Determine the value of following trigonometric expression:
If tan 4θ = cot 14θ, then find the value of cos 9θ.
The minimum value of 45 sin2 θ + 28 cos2 θ is
If 1 + sin 2θ = p2 and sin3 θ + cos3 θ = q then Which of the following is true ?Â
1. q3 – 2p + ...