Yes you are right Pradeep. Java does pass by reference only.
But inside the method m1, the received object is stored in a reference variable 'mx' and that object is local to that method. You are reassigning the local 'mx' variable to point to a new object and NOT the actual object being passed from your main() method.
...In the book its given as the object created at line 4 is eligible for garbage collection but i think its line 3 onject that is eligible for garbag collection. can i gert a clarification
Still, the object created in line 3 is being referred by the reference variable 'x'. Only the object being pointed by the reference variable 'x2' is lost since 'x2' is being made point to the same object as that of 'x4'.
Does that help Pradeep?