A method call includes a list of (potentially no) arguments being passed to the method. Arguments are passed using a style of argument passing that is known as pass-by-value, which is demonstrated in Listing 2-45.
Employee emp = new Employee("John Doe"); int recommendedAnnualSalarylncrease = 1000; printReport(emp, recommendAnnualSalarylncrease); printReport(new Employee("Jane Doe"), 1500);
Pass-by-value passes the value of a variable (the reference value stored in emp or the 1000 value stored in recommendedAnnualSalarylncrease, for example) or the value of some other expression (such as new Employee("Jane Doe") or 1500) to the method.
Because of pass-by-value, you cannot assign a different Employee object's reference to emp from inside printReport() via the printReport() parameter for this argument. After all, you have only passed a copy of emp's value to the method.
Was this article helpful?