Chapter 8 Object-Based Programming 425 1 // Fig.
Chapter 8 Object-Based Programming 425 1 // Fig. 8.19: TimeTest6.java 2 // Chaining method calls together with the this reference 3 4 // Java extension packages 5 import javax.swing.*; 6 7 // Deitel packages 8 import com.deitel.jhtp4.ch08.Time4; 9 10 public class TimeTest6 { 11 12 // test method call chaining with object of class Time4 13 public static void main( String args[] ) 14 { 15 Time4 time = new Time4(); 16 17 // chain calls to setHour, setMinute and setSecond 18 time.setHour( 18 ).setMinute( 30 ).setSecond( 22 ); 19 20 // use method call chaining to set new time and get 21 // String representation of new time 22 String output = 23 “Universal time: ” + time.toUniversalString() + 24 “nStandard time: ” + time.toString() + 25 “nnNew standard time: ” + 26 time.setTime( 20, 20, 20 ).toString(); 27 28 JOptionPane.showMessageDialog( null, output, 29 “Chaining Method Calls”, 30 JOptionPane.INFORMATION_MESSAGE ); 31 32 System.exit( 0 ); 33 } 34 35 } // end class TimeTest6 Fig. 8.19 Concatenating method calls. Note that the purpose of the example in Fig. 8.18 and Fig. 8.19 is to demonstrate the mechanics of concatenated method calls. Many Java methods return references to objects that can be used in the manner shown here. It is important to understand concatenated method calls as they appear frequently in Java programs. Good Programming Practice 8.9 For program clarity, avoid using concatenated method calls. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision personal web hosting services