Java Learning Note 15--Reference delivery
Example One
- Class demo{
- public Int temp = 30;
- }
- Public class T {
- public static void Main (string[] args) {
- //TODO auto-generated method stub
- Demo D1 = New demo ();
- D1.temp = 50;
- System.out.println ("Fun () method call before:" +d1.temp);
- Fun (D1);
- System.out.println (after the "fun () method call:" +d1.temp);
- }
- public static void Fun (Demo D2) {
- D2.temp = 1000;
- }
- }
Memory Analysis:
Example Two
[Java]View Plaincopy
- Public class T {
- public static void Main (string[] args) {
- //TODO auto-generated method stub
- String str1 = "Hello";
- System.out.println ("Fun () method call before:" +STR1);
- Fun (STR1);
- System.out.println ("Fun () method call before:" +STR1);
- }
- public static void fun (String s2) {
- S2 = "MLDN";
- }
- }
Memory analysis
Example Three
[Java]View Plaincopy
- Class demo{
- String temp = "Hello";
- }
- Public class T {
- public static void Main (string[] args) {
- //TODO auto-generated method stub
- Demo D1 = New demo ();
- D1.temp = "World";
- System.out.println ("Fun () method call before:" +d1.temp);
- Fun (D1);
- System.out.println (after the "fun () method call:" +d1.temp);
- }
- public static void Fun (Demo D2) {
- D2.temp = "MLDN";
- }
- }
Memory analysis
This procedure is exactly the same as the process of example one, and example two is special, because string is a special class whose contents cannot be changed.
Java Learning Note 15--Reference delivery