Home Segments Top Top Previous Next

884: Mainline

Suppose, by way of illustration, that you define the following thread. When run, by calling the start method in main, the thread prints Looping..., as fast as it can, ad nauseam.

public class DemoThread extends Thread { 
 public static void main (String argv []) { 
  DemoThread thread = new DemoThread(); 
  thread.start(); 
 } 
 public void run () { 
  while (true) { 
   System.out.println("Looping..."); 
  } 
 } 
} 

Note that the Thread class is provided by the java.lang package.