Lesson 4.7 · Trace it
Trace: local scope (Java)
Java code5 rows to fill2 marks
Complete the trace table for this Java code. [2]
Line 1: public static void main(String[] args) {Line 2, indented 1 level: int x = 10;Line 3, indented 1 level: int result = makeFive();Line 4, indented 1 level: System.out.println(x);Line 5, indented 1 level: System.out.println(result);Line 6: }Line 7:Line 8: static int makeFive() {Line 9, indented 1 level: int x = 5;Line 10, indented 1 level: return x;Line 11: }
Fill in one row each time a line changes x or result, or prints something. The table already has the right number of rows. In each row, write only what that line changes; you can leave the other cells empty or copy their values down. Write values the way Java shows them: 3 and 3.0 are different, and text goes in quotes. In the output column, write exactly what appears on screen, with no quotes around it.
| Row | x | result | output |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 |