Domanda di colloquio di 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?

Risposte di colloquio

Anonimo

4 feb 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.

Anonimo

11 mag 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.