Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TASK 1.1
- private void callerSideEffect() {
- myWindow.clearOut();
- //actual parameters
- int[] arrayActual = {1, 8, 16, 4, 20}; //array of int as reference type
- int intActual = arrayActual[0]; //element of array as value type
- calledSideEffect(arrayActual, intActual);
- myWindow.writeOutLine("\nAFTER METHOD CALL:");
- myWindow.writeOutLine("The value of intActual after method call is: " + intActual + "\nThe value of arrayActual after method call is: " + arrayActual[0]);
- }
- private void calledSideEffect(int[] arrayFormal, int intFormal) { //formal parameters
- arrayFormal[0]++; //1 incremented by 1
- //above arrayFormal equals to the arrayActual (references to the same address, so the address after call is not changed)
- intFormal++; //also incremented by 1
- myWindow.writeOutLine("ON METHOD CALL:");
- myWindow.writeOutLine("The value of arrayFormal on method call is: " + arrayFormal[0] + "\nThe value of intFormal on method call is: " + intFormal );
- }
- //TASK 1.3
- private void callerSwapParameters() {
- myWindow.clearOut();
- //actual parameters
- int n1 = 8;
- int n2 = 12;
- calledSwapParameters(n1, n2);
- myWindow.writeOutLine("\nAFTER METHOD CALL:");
- myWindow.writeOut("The value of n1 after the call is: " + n1 + "\nThe value of n2 after the call is: " + n2);
- //this methods values will be different to the calledSwapParameters values
- }
- private void calledSwapParameters(int n2, int n1) {
- myWindow.writeOutLine("ON METHOD CALL:");
- myWindow.writeOutLine("The value of n1 on the method call is: " + n1 + "\nThe value of n2 on the method call is: " + n2);
- //ESSENTIALLY, SWAPPED ON METHOD CALL
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement