public Class A { public static String s = "s"; public static int i = 0; public int j = 1; public static String getStaticString() { int k = 2; return s; } public String getString() { int l = 3; return "something"; } }
根据很多资料,static variables
是存在heap
中的Perm
代,primitive
类型存在stack
中。
问题:
1、s
是存在heap
中的Perm
代,i
,j
,k
,l
存在哪呢?
2、static
方法存在哪?非static
方法存在哪?也就是说,getStaticString
存在哪,getString
方法存在哪?
j exists in the instance of A, and the instance of A exists in the heap.
k and l are primitives created on the stack (in the method body), so there is a stack.