What is the output of the following Java program?

1
2
3
4
5
6
7
8
class Sum {
    static int sum = 0;
    static void add(int i) { i++; }
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) add(sum);
        System.out.println(sum);
    }
}

Select one:

  • a. 100
  • b. 9
  • c. 10
  • d. 0
  • e. 45

The "add" method increments the parameter "i", which is a copy of the argument "sum". The value of "sum" never changes. The correct answer is: 0

Related Posts

0 Comments

12345

    00