// program to test functions that return objects class newobj { public static void main(String[] args) { int x; int y; A m; A n = new A(); x = n.setx(5); m = n.makecopy(); x = m.setx(6); x = n.getx(); y = m.getx(); if ((x+y)==11) System.out.println("I love compilers\n"); else System.out.println("I hate compilers\n"); // only if typechecker exists: x = ((m.makecopy()).setx(10)); if (x==10) System.out.println("I really love compilers\n"); } } class A { int x; public int getx() { return x; } public int setx(int y) { x = y; return x; } public A makecopy() { int r; A n = (new A()); r = n.setx(x); return n; } }