public class HomeworkFour { public static void foo(int[] a, int[] b) { // part 2: what do things look like when we get here? int[] c = {3, 5, 7, 9}; a = c; for (int i = 0; i b[i] = a[i]; } // part 3:...

public class HomeworkFour { public static void foo(int[] a, int[] b) { // part 2: what do things look like when we get here? int[] c = {3, 5, 7, 9}; a = c; for (int i = 0; i b[i] = a[i]; } // part 3: what do things look like when we get here? } public static void main(String[] args) { int[] a = {2, 4, 6, 8}; int[] b = new int[a.length]; int[] c = b; // part 1: what do things look like when we get here? foo(a, b); // part 4: what do things look like when we get here? System.out.println(a[2] + " " + b[2] + " " + c[2]); } } 1. Construct a single memory diagram that shows what things look like in memory just BEFORE the call to foo(). Include both the stack and the heap in your diagram. Begin by copying the following template into your text file, and then use text characters to complete the diagram. 2. stack | heap 3. +------------+ 4. | main | 5. | +----+ | +---+---+---+---+ 6. | a | --|---+--------->| 2 | 4 | 6 | 8 | 7. | +----+ | +---+---+---+---+ 8. | | 9. | +----+ | 10.| b | | | 11.| +----+ | 12.| | 13.| +----+ | 14.| c | | | 15.| +----+ | 16.+------------+ 17. Construct a single memory diagram that shows what things look like in memory AT THE START of the execution of foo() – just before its first statement is executed. Include both the stack and the heap in your diagram. 18. Construct a single memory diagram that shows what things look like in memory AT THE END of the execution of foo() – just before it returns. Include both the stack and the heap in your diagram. 19. Construct a single memory diagram that shows what things look like in memory AFTER the call to foo() has returned – just before the print statement executes in main().
May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here