Question: 2. This question is about code generation. The first two parts make reference to the following program fragment in a Java-like language: class MyInt {

 2. This question is about code generation. The first two parts

2. This question is about code generation. The first two parts make reference to the following program fragment in a Java-like language: class MyInt { private int n; public MyInt (int j) { n=j; } public int f (int x) { n=n+1; return n*x; } public MyInt g (int x) { int j = x+n; MyInt r = new MyInt(j); return r; } } (a) Consider an invocation of the form a.g(z) for variables a (of type MyInt) and z (of type int). Describe the locations in memory of the variables x, j, n, and r (making reference to the stack, activation frame, symbol table, or heap as appropriate), and explain the reason for your answer. i. Briefly describe the location of the variable x, and the reason for this. [4 marks] ii. Describe the location of the variable j. Does it have any simple relationship to the location of x? Briefly explain your answer. [8 marks] iii. Describe the location of the variable n. Does it have any simple relationship to the location of x or j? Briefly explain your answer. [8 marks] iv. Describe the location of the object r. Does it have any simple relationship to the location of x, j, or n? Briefly explain your answer. [8 marks]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!