LearnFrenzy
Sign in Take a free test

Methods and Recursion · Predict the Output · Question 20

Order in which method arguments are evaluated Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 20 Back to Exercise

What is the output of the following Java program?

Main.java
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links