Java对象在内存图示

class Point {
    int x;
    int y;

    void display() {
        System.out.printf("(%d,%d)
",x,y);
    }
    
}

class Line {
    Point start;
    Point end;
}
class OOP {
    public static void main(String[] args) {

    Point a;
    Point b;
    a = new Point();
    a.x = 2;
    a.y = 1;

    b = new Point();
    Point c = a;
    a.display();
    b.display();
    c.display();


    Line l = new Line();
    l.start = a;
    l.end = b;
    }
}


左边模板是在栈里面存储,堆一般是动态存储

原文地址:https://www.cnblogs.com/zhangmingzhao/p/7256683.html