62,620
社区成员
发帖
与我相关
我的任务
分享

public class Test{
private int i = 0;
private String s = "abc";
public static void method(){
int k = 1;
String b = "bcd";
}
public static void main(String[] arges){
int w = 2;
String d = "qwe";
Test t = new Test();
t.method();
}
}
w 与 d 保存在那里?
那么,i 与 s 保存在栈 还是在 堆里?
还有就是k 与 b 保存在 栈 还是在 堆 里?
public static void main(String args[]){
A parent = new A();
//more code
}
class A{
B child = new B();
int e;
//more code
}
class B{
int c;
int d;
//more code
}

class instance{
int age = 0;
String name = "";
……
}instance tan = new instance();时其中的int age并不是保存在栈中,而是在堆里面。Mainclass m = new MainClass();