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?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly