public class references
{public static input in = new input();
public static void main(String[] args) throws IOException
{
// This example illustrates that variables only hold references to objects that are created
// they don't hold the objects themselves
Integer a = new Integer(12);
Integer b = a;
a = new Integer(14);
System.out.println(a+ " "+b);
// Example 2
//class person
//{private String name;
// person(String n)
// {name = n;
//}
//public void changename(String n)
//{name = n;
//}
//public String toString()
// {return name;
// }
//}
person p = new person("Joe");
person p2 = new person("Tom");
ArrayList ar = new ArrayList();
ar.add(p);
ar.add(p2);
p.changename("Jack");
// this will print out Jack and Tom not Joe and Tom as you might expect
// this is because p and ar[1] now both reference the same object and when
// we change 1 we change the other
for (int x=0; x< ar.size(); x++)
{person pe = ar.get(x);
System.out.println(pe);
}
}
}