import Rational; public class RatTest { public static void main(String[] args) { Rational A = new Rational(2,3); Rational B = new Rational(3,2); Rational C = new Rational(); System.out.println("1: (wie erwartet)"); System.out.println("A = " + A.toString() ); // Ausgabe der Zahlen- System.out.println("B = " + B.toString() ); // objekte System.out.println("C = " + C.toString() ); A.add(B); C = Rational.xadd(A,B) ; System.out.println("2: (wie erwartet)"); System.out.println("A = " + A.toString() ); // Ausgabe der Zahlen- System.out.println("B = " + B.toString() ); // objekte System.out.println("C = " + C.toString() ); A.setNumerator(2); A.setDenominator(3); B.setNumerator(4); B.setDenominator(5); System.out.println("3: (...)"); System.out.println("A = " + A.toString() ); // Ausgabe der Zahlen- System.out.println("B = " + B.toString() ); // objekte System.out.println("C = " + C.toString() ); C = A; System.out.println("4: (vor der Addition...)"); System.out.println("A = " + A.toString() ); // Ausgabe der Zahlen- System.out.println("B = " + B.toString() ); // objekte System.out.println("C = " + C.toString() ); A.add(B); System.out.println("5: (...danach eine gute Uebung mit dem Debugger :-)"); System.out.println("A = " + A.toString() ); // Ausgabe der Zahlen- System.out.println("B = " + B.toString() ); // objekte System.out.println("C = " + C.toString() ); } } /* Und wie konnte C auf mystische Weise nach dem letzen Befehl den Inhalt von A erhalten? Antwort: Gar nicht. C wurde schon VORHER zu A definiert --> C = A; C zeigt also auf die gleiche Speicherzelle wie A! */