Code Analysis series Memory execution process

Source: Internet
Author: User

1, Memory execution process: (six:01:32:08-->)

Package primary;

public class Main {
public static void Main (String args[]) {
Main m= new Main ();
int day = 15;
Birthday B1 = new Birthday (27,11,1988);
Birthday b2 = new Birthday (23,04,2013);
M.change1 (day);
M.change2 (B1);
M.change3 (B2);
B1. Display ();
B2. Display ();
}
void change1 (int num) {
num = 123;
}
void Change2 (Birthday b) {
b = new Birthday (04,01,1989);
}
void Change3 (Birthday b) {
B.setday (B.setmonth); B.setyear (2015);

}
}

Class birthday{
int Day;int month;int year;
Birthday (int _day, int _month, int _year) {
Day = _day;month = _month;year = _year;
}
void Display () {
System.out.println ("Birthday is:" +year+ "-" +month+ "-" +day ");
}
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;
}

}

Output:

Birthday is:1988-11-27
Birthday is:2015-1-26

2, involving knowledge:

Stack memory and heap memory, reference passing and value passing, stack variables are freed, and heap memory is reclaimed by GC after a certain amount of time.

  

Code Analysis series Memory execution process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.