Welcome to the Ranch
Please use the
code button. Fortunately I can apply it to your code, and you can see how much better it looks
I think you have a misunderstanding about pass‑by‑reference and pass‑by‑value. There is a long discussion about it
here; have a look at that when you have a week to spare.
The rules about pass‑by‑reference are very simple in
Java: it doesn’t exist. If it used pass‑by‑reference, you could write something like this
But it doesn’t, so you can’t. All that code can be compiled and executed in Java, but it doesn’t print 234. The original f reference, outside the method, remains unchanged. So it prints Foo 123. The only Foo references changed are those in the method.
Remember, when people tell you that reference types are pass‑by‑reference and primitives are pass‑by‑value, those people are telling you rubbish.