Java学习——方法中传递参数分简单类型与复杂类型(引用类型)

package hello;

public class PeopleAndMoney {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
          double y=0.8; 
          People zhang=new People();
          zhang.setMoney(8888);
          A a=new A();
          System.out.println("在方法f被调用之前对象zhang的money是:"+zhang.money+"  y的值是"+y);
          a.f(y,zhang); 
          System.out.println("在方法f被调用之后main方法中y的值仍然是:"+y);
          System.out.println("在方法f被调用之后main方法中对象zhang的money是:"+zhang.money);
       }
    }


class People {
    int money;

    void setMoney(int n) {
        money = n;
    }
}

class A {
    void f(double y, People p) {
        y = y + 1;
        p.setMoney(100);
        System.out.println("参数y的值是:" + y);
        System.out.println("参数对象p的money是:" + p.money);
    }
}

 

 

posted on 2018-10-13 17:20  蔡军帅  阅读(96)  评论(0编辑  收藏  举报