Java uses pass by value for passing parameters on a method call. What does this mean if the parameter is a primitive data type? What does this mean if the parameter is a reference to an object?
What will be an ideal response?
Pass by value means that the value associated with the actual parameter is copied into the memory location of
the formal parameter when the method is called. The formal and actual parameters occupy distinct locations in memory. If the
parameter is a primitive data type, any modifications made to the formal parameter during the execution of the method will most
likely not be reflected in the actual parameter. If the parameter is a reference to an object, then it holds the location of an object.
While the formal and actual parameters will be distinct, they will both hold the address of the object and will be aliases. If the
method modifies the object, then those modifications will be apparent when referencing the object using the actual parameter
after the method terminates.
You might also like to view...
When only one decision needs to be made, it does not require a nested selection structure.
Answer the following statement true (T) or false (F)
Only one path in a selection structure can include instructions that declare variables, perform calculations, and so on.
Answer the following statement true (T) or false (F)