Question 20
Back to Exercise
What is the output of the following Java program?
public class Main {
static int counter = 0;
static int next() { return ++counter; }
static String join(int a, int b, int c) { return a + "-" + b + "-" + c; }
public static void main(String[] args) {
System.out.println(join(next(), next() * 10, next() + 100));
}
}
- A 1-20-103 Correct
- B 3-20-101
- C 1-10-100
- D 1-20-100
Correct Answer: Option A
Java evaluates arguments left to right: next() returns 1, then 2 (×10), then 3 (+100).
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!