Question 6
Back to Exercise
What is the output of the following Java program?
class Engine {
static { System.out.print("S "); }
{ System.out.print("I "); }
Engine() { System.out.print("C "); }
}
public class Main {
public static void main(String[] args) {
System.out.print("M ");
new Engine();
new Engine();
System.out.println();
}
}
- A M S I C I C Correct
- B S M I C I C
- C M S I C S I C
- D M I C I C S
Correct Answer: Option A
Engine is initialised when first used (the first new), so S prints after M, and only once.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!