Topic 6.6: Working with Methods and Encapsulation - Determine the effect upon object references and primitive values when they are passed into methods that change the values Flashcards
1
Q
This means a copy of the actual parameter’s value is passed to the formal parameter in a method.
A
What is pass-by-value in Java?
2
Q
For this Java uses “pass-by-value” for both primitive types and object references.
A
How does Java handle parameter passing in methods?
3
Q
What is pass-by-value in Java?
A
This means a copy of the actual parameter’s value is passed to the formal parameter in a method.
4
Q
How does pass-by-value work for object references?
A
- Object references are passed by value, meaning a copy of the reference (memory address) is passed to the method.
- When an object reference is passed to a method, the method receives a copy of the reference, not a copy of the object itself.
- Any changes made to the object through the reference inside the method will affect the original object outside the method.
5
Q
How does Java handle parameter passing in methods?
A
For this Java uses “pass-by-value” for both primitive types and object references.
6
Q
What happens when primitive types are passed to a method?
A
- Primitive types are passed by value, meaning a copy of the actual value is passed to the method.
- Any changes made to the parameters inside the method do not affect the original values outside the method.