Java Magazine, Sept/Oct 2018
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2018 84 fix this ber and if either of the cooks writes a new number on her own copy the other cooks copy remains unchanged However if Jamie goes directly to Rachels files then either of them changing the value will cause both of them to see the new number if they look at the file after the change is made These two forms are exact analogies to how data can be passed into methods in Java Furthermore the consequences of the visibility of changes are the same In Java the value of a variable is always passed by copying that value into a new variable that is local or exclusive to a particular method invocation Indeed if you call the same method three times three separate copies will have been created This is called pass by value or pass by copy It is equivalent to Jamie getting a piece of paper with something written on it However what a variable is and therefore the significance of what is written on the paper depends on the data type A variable of primitive type contains the actual value represented But for any data that is of object type that is anything except one of the eight primitive types the value of the variable describes how to find the data That is the variable contains information equivalent to the filing cabinet and sheet number where the information can be found In the log method two arguments are passed One Message is an object The other is a primitive boolean From the analogy this means that for Message the log method has instructions on where to find the data and that potentially any changes it makes to that data would alter the original value seen after the log call However for the status value the log method gets a copy of the true or false value and it has no ability to interact with the original data in the caller Therefore it has no chance of changing the value that is printed by the printf call after it returns So at this point you can see that the assignment in line n1 would change the message code to zero if it works at all therefore any final output message cannot include the error code 255 This means that option B must be incorrect This also means that the assignment to status immediately after line n1 afects the local copy of the status value and cannot change the value of handled in the caller Importantly this would still be the case even if the variable were called status in the caller These are entirely
You must have JavaScript enabled to view digital editions.