Pregunta de entrevista de eBay

Describe pass by reference. You have a program with a method changeMe() that takes a string. In the main method, a string is set to "Hello" and it is passed to changeMe(). The changeMe() method sets the string to "I'm changed". In the main method, after call to changeMe(), there is a print statement for the string. What is printed?

Respuestas de entrevistas

Anónimo

4 de feb de 2011

"Hello" because that is a pass by value. This was the first question he asked. I felt it threw me off because he talked about pass by reference and he also didn't state if it was language specific because he said these were general programming questions. Depending on the language you could have a case where it's changed. If I was coding, I would run the program to test it so what would these questions matter.

Anónimo

11 de may de 2011

Even if the changeMe() method try to change the passed object, it will not change it. When you print the value in Main method it will still print Hello because String in immutable. When changeMe() method changes the passed value a new object will get created.