Originally posted by Doug Patterson:
I hope this is the place to ask this.
In Chapter 3, self-test question 18 -- I have never seen this before. Method "Two fix()" is defined in class PassO, but looks like a method of class Two!
Doug,
Welcome to the
Java Ranch!
I'm not sure that I understand your question but I will try to explain how the code works.
The start method creates an instance of class Two and then prints the default value of t.x. The default value is zero.
The reference to the instance, t, is passed to the fix method where the value of t is changed to 42. When the method returns both references, t and t2, refer to the same instance so the value 42 is printed twice.
I hope that helps.