I am thinking about memory allocation in Java i.e in which memory location methods, fields and objects are stored.
Suppose I have 2 classes
import java.util.*;
class ABC
{
int field;
List<Integer>l;
}
class XYZ
{
int x,y,z;
static int p;
void fun(ABC a){
a.field = 10;
a.l = new ArrayList<Integer>(10);
a.l.add(10);
}
}
public class Simulator{
public static void main(String[] arg){
XYZ tmp_1 = new XYZ();
ABC tmp_2 = new ABC();
tmp_1.fun(tmp_2);
System.out.println(tmp_2.l);
}
}
Now where will the memory be allocated for each of the data members,functions and objects be allocated ?
My thoughts are objects, data-members will be stored in Heap but I am not sure about functions and their data members ?