我对Java Memory Segmets非常困惑。下面我创建了一个小程序,我在每行附近评论了它在我看来保存的内存。如果我理解正确与否,请告诉我。
public class Person
{
private int salary; // non-initialize value -> Bss segment
private int id = 5; // initialize value -> Data Segment.
private String name = new String("Johani"); // refrence will be saved in data while the object in heap.
public static int num = 5; // static initialize value -> Data Segment.
public void myFunc()
{
int i = 10; // Stack
String myString = new String("abcd"); // refernce in Stack, while object in heap.
}
}
如果我有些错误,请告诉我。