Assignment with objects is a bit tricky. : Class Object « Class Definition « Java Tutorial






class Number {
  int i;
}

public class MainClass {
  public static void main(String[] args) {
    Number n1 = new Number();
    Number n2 = new Number();
    n1.i = 9;
    n2.i = 47;
    System.out.println("1: n1.i: " + n1.i + ", n2.i: " + n2.i);
    n1 = n2;
    System.out.println("2: n1.i: " + n1.i + ", n2.i: " + n2.i);
    n1.i = 27;
    System.out.println("3: n1.i: " + n1.i + ", n2.i: " + n2.i);
  }
}
1: n1.i: 9, n2.i: 47
2: n1.i: 47, n2.i: 47
3: n1.i: 27, n2.i: 27








5.17.Class Object
5.17.1.Getting java.lang.Class: Information about your object
5.17.2.Comparing Objects
5.17.3.Class Object
5.17.4.Storing a reference to the String object as type Object
5.17.5.The 'Class' class also brings the possibility of creating an object without using the new keyword.
5.17.6.Assignment with objects is a bit tricky.
5.17.7.Demonstrate Run-Time Type Information.