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:
- class Test {
- public static void main(String args[]) {
- int num1 = 10, num2 = 20, result;
- result = calc(num1, num2);
- System.out.println(result);
- }
- }
- // insert code here
- } 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)- A2% (1)
- B2% (1)
- D84% (42)
- E4% (2)
- F8% (4)
Community Discussion
No community discussion yet for this question.