java 内存分析之堆栈空间
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package Demo; public class Demo { public static void main(String[] args) { Demo demo = new Demo(); int date = 9; BirthDate d1 = new BirthDate(7, 7, 1970); BirthDate d2 = new BirthDate(5, 8, 2000); demo.change1(date); demo.change2(d1); demo.change3(d2); } public void change1(int i) { i = 1234; } public void change2(BirthDate b) { b = new BirthDate(22, 2, 2004); } public void change3(BirthDate b) { b.setDay(22); } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package Demo; public class BirthDate { private int day; private int month; private int year; public BirthDate(int d, int m, int y) { day = d; month = m; year = y; } public void Display() { System.out.println(day+"-"+month+"-"+year ); } public int getDay() { return day; } public void setDay(int day) { this.day = day; } public int getMonth() { return month; } public void setMonth(int month) { this.month = month; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } }
内存分析图: