In your opinion, Is Java Pass By Value or Pass By Reference?
You may note that this question asks you for your opinion, even though it is technical. Not all technical questions have finite answers. Some may be relevant to the work you do or the type of experience you have writing programs. It is okay to state an opinion about a topic as long as you can support your answer. When asked a question of this type during the interview with Salesforce, you can anticipate follow-up questions asking why you believe this to be the right answer.
"This is an interesting question. If you ask the current Java developers working here at Salesforce, some will say that Java is pass by value, while the others will say pass by reference. In my opinion, Java is pass by value. This is how it is defined in the Java Spec. Java method parameters directly associate variable passing and method calling. The exception is when we pass a reference of complex types defined as method parameters, the memory address is copied to a new reference variable."
Community answers are written by other candidates practicing this set. Reading how others frame the same question is one of the fastest ways to sharpen your own.
Anonymous Answer
Java is a pass-by-value language as Java method parameters directly associate variable passing and method calling. There can be some complexity involved when passing variables and through a method, because these are then copied as a new object reference.
Marcie's Feedback
Nice! The interviewer will appreciate that you've clearly and directly answered the question. Can you possibly include an example of a pass-by-reference?
Unlock all 20 Salesforce CRM questions
Unlock expert responses for technical Salesforce and Java integration interviews.
Get Started