0
Passing object into method
I have this peace of code "public double distance(Point another) { int xDiff = this.x - another.x; int yDiff = this.y - another.y; return Math.sqrt(xDiff*xDiff + yDiff*yDiff);"} In this method as parameter i have object? ?If that is true and i dont see other explanation because i'm sending him object from main "Point p=new Point();" how i can do that because i never made object called "another", does this mean that i declared object "another" who can receive other objects??
2 odpowiedzi
+ 2
It is just a pointer to the object location in memory. You're passing it to your method, and inside that method you can access this object via pointer with "another" name. Object will be the same. You also can pass Null pointer, that doesn't point to any object.
0
@Roman yes, thank you just needed clarification and confirmation.