参数名称

参数传递方式  1. 值传递 2. 引用传递.

1. 值传递(Java的方式):传递的是的值的拷贝

2. 引用传递:传递的是的存储值的引用

 

由于值传递的方式注定了Java的方法的功能:

1. 在方法体内都,无法修改作为参数的基本类型值

2. 在方法体内部,能够修改对象的内容。

3. 在方法体内部,无法将参数外的引用指向新的对象

View Code
public class Employee{

      public double salary=5000.0d;    
}

public class EmployeeTest{
    
     public static void changePrimitiveType(int x){
           x = 2;
     }    
    
     public static void changeObjectContent(Employee employee){
          employee.salary *= 1.1d;          
     }
    
    public static void changeObjectReference(Employee employee){
         employee = new Employee();
    }

    public static void main(String[] args){
          int x = 3;
          System.out.println("Before change method x := " + x);
          changePrimitiveType(x);
          System.out.println("After change method x : =  " + x);
          
          Employee employee = new Employee();
          System.out.println("Before change method" + employee.salary);
          changeObjectContent(employee);
          System.out.println("After change method" + employee.salary);
          
           Employee mEmployee = new Employee();
           System.out.println("Before change method " + mEmployee.salary );
           mEmployee.salary = 2000.0d;
           changeObjectReference(mEmployee);
           System.out.println("After change method " + mEmployee.salary);
    }
}
    

转载于:https://www.cnblogs.com/papertigerv5/archive/2012/09/25/2703105.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值