The main method of the UseClockStdout program (given below) creates an object (tClockStdout) of the class ClockStdout, and then calls tClockStdout's start method. However, the class ClockStdout does not itself declare a start method, and so it is java.lang.Thread's start method that gets called. As explained earlier, this does two things:
0805: public class UseClockStdout { // UseClockStdout.java
0806: public static void main(String[ ] args) {
0807: System.out.println("UseClockStdout program");
0808: ClockStdout tClockStdout = new ClockStdout();
0809: tClockStdout.start();
0810: for ( int count = 0; count < 8 ; count++ ) {
0811: System.out.println("count is: " + count);
0812: try { Thread.sleep(1000); }
0813: catch ( InterruptedException tInterruptedException ) { }
0814: }
0815: System.out.println("UseClockStdout program");
0816: }
0817: }
Here is the sort of output that the program produces:
UseClockStdout program count is: 0 Sat Jun 14 15:49:15 GMT+01:00 1997 count is: 1 count is: 2 Sat Jun 14 15:49:17 GMT+01:00 1997 count is: 3 count is: 4 Sat Jun 14 15:49:19 GMT+01:00 1997 count is: 5 count is: 6 Sat Jun 14 15:49:21 GMT+01:00 1997 count is: 7 UseClockStdout program Sat Jun 14 15:49:23 GMT+01:00 1997 Sat Jun 14 15:49:25 GMT+01:00 1997 Sat Jun 14 15:49:27 GMT+01:00 1997 Sat Jun 14 15:49:29 GMT+01:00 1997 ...You can see that the output is from both threads, and that the program will not finish because the tClockStdout thread is an infinite loop. So, if you execute this program, you will need to press Ctrl/C to stop its execution.