If (result<0) System.out.println(surface1.getName()+"is the smaller one");
else If (result>0) System.out.println(surface2.getName()+"is the smaller one");
else System.out.println("The surface has the same area"); 從以上程序中可以看出,surface1與surface2發生交互從而得到結果result。首先它計算出自己的面積,然后計算出surface2的面積,最后再比較它們兩個之間的面積的大小。 以上過程用UML序列圖可以描述為下圖: