回顾方法的调用

回顾方法的调用

package com.oop;

public class Demo03 {
    public static void main(String[] args) {
        //实际参数和形式参数的类型要对应!
        int add = Demo03.add(1, 2);
        System.out.println(add);
    }

    public static int add(int a,int b){
        return a+b;
    }
}
package com.oop;
//值传递
public class Demo04 {
    public static void main(String[] args) {
       int a = 1;
        System.out.println(a);//1
        Demo04.change(a);
        System.out.println(a);//1
    }
    //返回值为空
    public static void change(int a){
        a = 10;
    }
}
package com.oop;
//引用传递:对象,本质还是值传递
public class Demo05 {
    public static void main(String[] args) {
        Person person = new Person();
        System.out.println(person.name);//null
        Demo05.change(person);
        System.out.println(person.name);//汉化
    }
   public static void change(Person person) {
        person.name = "汉化";
   }
}

//定义了一个person类,有一个属性:name
class Person{
    String name;//null
}

上一篇:readonly 和 shallowReadonly


下一篇:论文阅读 之 Joint Detection and Identification Feature Learning for Person Search