Question: Programming Languages Given the following program, For each identifier in the following Java code explain if its Stack or Heap bound, public class Example {

Programming Languages

Given the following program,

For each identifier in the following Java code explain if its Stack or Heap bound,

public class Example

{

static int n = 3;

public static void main(String[] args) {

int k;

k = n;

Controller control = new Controller(k);

control.compute();

}

class Controller

{

int n;

Controller(int n) {this.n = n;}

void compute() {

int i, m;

int sum = 0;

String message;

Functor func;

for(i = n; i > 0; i--) {

func = new Functor();

m = func.calculate(i);

sum = sum + m;

}

message = Sum of factorials from 1 to + n +

is + sum;

System.out.println(message);

}

}

class Functor

{

int calculate(int n) {

int temp;

temp = n 1;

if (n > 0) { return n * calculate(temp); }

else {return 1;}

}

}

Extract the following

Extract the following

List all static variables,

stack-dynamic variables,

explicit heap-dynamic variables, and

implicit heap-dynamic variables.

Class members are part of a class instance. Where they live depends upon where the instance lives. If you declare an instance of a class as an automatic variable, then it is on the stack. If you allocate it with operator new, then it is on the heap.

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!