nerdexam
Oracle

1Z0-850 · Question #30

Given: 1. class Test { 2. public static void main(String args[]) { 3. int num1 = 10, num2 = 20, result; 4. result = calc(num1, num2); 5. System.out.println(result); 6. } 7. } 8. // insert code here…

The correct answer is D. static int calc(int n1, int n2) { return n1 + n2; }. See the full explanation below for the reasoning.

Question

Given:
  1. class Test {
  2. public static void main(String args[]) {
  3. int num1 = 10, num2 = 20, result;
  4. result = calc(num1, num2);
  5. System.out.println(result);
  6. }
  7. }
  8. // insert code here
  9. } Which, inserted at line 8, produces the output 30?

Options

  • Astatic int calc(int n1, int n2) { return; }
  • Bpublic int calc(int n1, int n2) { return n1 + n2; }
  • Cpublic int calc(int n1, int n2) { return; }
  • Dstatic int calc(int n1, int n2) { return n1 + n2; }
  • Estatic void calc(int n1, int n2) { return (n1 + n2); }
  • Fstatic int calc(int n1, int n2) { return n1, n2; };

How the community answered

(50 responses)
  • A
    2% (1)
  • B
    2% (1)
  • D
    84% (42)
  • E
    4% (2)
  • F
    8% (4)

Community Discussion

No community discussion yet for this question.

Full 1Z0-850 Practice