Basic data type reference data type

Java is divided into basic data types (byte short int long float double char boolean) and reference data types (array class interface)

In the method call, the basic data type only transfers the value, and the variable does not change, while the reference data type changes the original variable if the reference data type is modified in the method. String is also a reference data type, but it does not change.

public class Test {
    
    
    public static void main(String[] args) {
    
    
        String a = new String("abc");
        int b = 5;
        int[] c={
    
    1,2,3,4};
        changeInt(a,b,c);
        System.out.println(a +"-"+ b +"-"+ Arrays.toString(c));
    }
 
    public static void changeInt(String a,int b,int[] c) {
    
    
        a = "123456";
        b = 10;
        c[0] = 5;
    }
}

operation result:
Insert picture description here

Guess you like

Origin blog.csdn.net/xiahuayong/article/details/107413059