[Solved] Java: Objects in parameters [closed]


Well the reason should be comprehended easily. It is just a simple way to pass information inside that method. In this manner, you are creating a method variable, who has a reference to the object being passed as an argument when the method is called. And you can use this information inside the method (i.e: the state of the object, use its method and so on).

Example:

public void carMove(Car c){
   System.out.println(c.toString() + " + c.hashCode());  //this will print some basic information about that object, based on the methods output
   }

Please take a look at this links:
Passing Information to a Method |
Defining a method

NOTE: It is almost the same as with primitive data types such as int, long and so on. There is just one slight difference ,Java passes arguments by value (in case of primitives, just their values, in case of objects, the value of the reference pointing to that object). For more on this: Pass-by-reference

solved Java: Objects in parameters [closed]