// purpose: demonstrate that if an object is changed all variables referring // to the object see the change; that is, none remember its prior contents import javax.swing.*; public class TwoObjectsThreeVariables { // method main(): program starting point public static void main( String[] args ) { JFrame w1 = new JFrame( "I call myself eeny" ); w1.setSize( 250, 150 ); w1.setVisible( true ); Pause.untilReady(); JFrame w2 = new JFrame( "I call myself meeny" ); w2.setSize( 250, 150 ); w2.setVisible( true ); Pause.untilReady(); JFrame w3 = w1; // variables w1 and w3 see the same object Pause.untilReady(); System.out.println ( "Title of the window w1 sees: " + w1.getTitle() ); System.out.println ( "Title of the window w2 sees: " + w2.getTitle() ); System.out.println ( "Title of the window w3 sees: " + w3.getTitle() ); Pause.untilReady(); w3.setTitle( "I call myself zambini" ); Pause.untilReady(); System.out.println ( "Title of the window w1 sees: " + w1.getTitle() ); System.out.println ( "Title of the window w2 sees: " + w2.getTitle() ); System.out.println ( "Title of the window w3 sees: " + w3.getTitle() ); } }