Question: In Java programming 3) Run the following code. The sum method in this program violates a design principle of the book (that methods should not
In Java programming
3) Run the following code. The sum method in this program violates a design principle of the book (that methods should not try to modify an argument) when it assigns 5 to a, and 6 to b. Certainly these values are changed; this can be seen by examining the value the sum method returns. But what about arguments x and y? Are their values changed, too? In other words: Do the assignments made in the method body have side effects in the main program? public class Area public static void main(String[] args) int x 2 int y 3: System.out.println ("x: " +x + " y: "+ y+ " Sum: " + sum (x, y)); Computes the sum of two arguments. @param a an int operand to be added eparam b another int operand @return the sum of a and b public static int sum (int a, int b) a5 return abi
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
