02值传递和引用传递

public class Demo02 {
    public static void main(String[] args) {
        int i=1;
        System.out.println(i);
        Demo02.change(i);//该方法并没有返回值
        System.out.println(i);

        Person person =new Person();
        System.out.println(person.age);
        Demo02.utter(person);//改变的是对象的属性
        System.out.println(person.age);
    }
    public static void change(int a){
        a=10;
    }
    public static void utter(Person c){
        c.age=10;
    }
}
class Person{
    int age;
}
运行结果:
1
1
0
10

posted @ 2021-04-17 21:24  且听_198  阅读(34)  评论(0)    收藏  举报