Pointers and References
In Java, one can�t write a procedure to swap the values of two int variables x and y. The following method and call does not change x and y:
public void notaSwap(int p1, int p2)
{int t= p1; p1= p2; p2= t;}
int x= 5; int y= 6; notaSwap(x,y);
But one can change the values of fields of a class:
public class Coord {int x; int y;}
// Swap x fields of p1 and p2
public static void Swap(Coord p1, Coord p2)
{int t= p1.x; p1.x= p1.y; p1.y= t;}