Java basic method parameter and return value passing: primitive type, reference type
How are method parameters and return values passed in memory? Let’s graph the entire execution of this
Basic types of
Code sample
Public class Text {public int changeNum(int a){system.out.println (" method before "+a); a=10; System.out.println(" method after execution "+a); return a; Public static void main(String[] args) {Text t=new Text();} public static void main(String[] args) {Text t=new Text(); Int x=1; x=t.changeNum(x); X accepts system.out.println (" method completed, main value of a "+x); }}Copy the code
The basic types are shown in the figure
Reference types
Code sample
Public class Text {public void chnangeArray(int[] x){system.out.println (" method before "+x[0]); x[0]=10; System.out.println(" after method execution "+x[0]); } public static void main(String[] args) { Text t=new Text(); Int a [] = new int [],1,2,3 {0}. t.chnangeArray(a); Int [] x=a; int[] x=a; Println (" method completed, value of ain main "+a[0]); }}Copy the code
Reference type diagram
I want to work my way up
Fly forward on the blades at the highest point
Let the wind blow dry tears and sweat
I want to work my way up
Waiting for the sun to watch its face
Little days have big dreams
I have my day
Let the wind blow dry tears and sweat
One day I will have my day