• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Question on Pass-by-value for Primitves & References

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Sybex Java certification study guide,
In self assessment test,There is a Question :

28. Which of the following statements accurately describes how variables are passed to methods?
A. Arguments are always passed by value.
B. Arguments are always passed by reference.
C. Arguments that are primitive type are passed by value.
D. Arguments that are passed with the & operator are passed by reference.

Now , i thought ,As i read ,also from Campfire story ,Java always passes by value ,not different for Primitves or references.
For Objects, copy of reference is passed.
So answer should have been - A
But here ,Answer is C.
So How to justify this answer or its wrong.???
How do we get to know in exam ,the context of Question ???

Thank you
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A is correct. (Technically, C is also correct.)
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer A is correct. It's always the value that's passed.

By the use of object the value is the reference to the object. So you're coping the reference value.

You're not copying the object itself, but only the reference to the object.

By primitives the value holds just the value of the primitive.
 
You didn't tell me he was so big. Unlike this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic