-1

I wondered why i can change the title of my current frame after passing it eg. to another class. If i pass my current frame in the constructor of another class by the this reference, why am i able to change the size or the title of the window? I thougt only values were passed by methods and no object instances.

I know this sounds a little confusing but its not a question about programming syntax but about how stuff works in java. I would be happy if someone could tell me the answer.

Einstein
  • 360
  • 1
  • 4
  • 15

1 Answers1

1

You are correct that objects are passed by reference, primitives are passed by value. If an object is passed, then, it keeps the references to all of it's fields. To fix this you must new a new object from the passed one.

grey00
  • 469
  • 2
  • 13