www.pudn.com > TIJc04.rar > Mugs.java


//: c04:Mugs.java 
// Java "Instance Initialization." 
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 
// www.BruceEckel.com. See copyright notice in CopyRight.txt. 
import com.bruceeckel.simpletest.*; 
 
class Mug { 
  Mug(int marker) { 
    System.out.println("Mug(" + marker + ")"); 
  } 
  void f(int marker) { 
    System.out.println("f(" + marker + ")"); 
  } 
} 
 
public class Mugs { 
  static Test monitor = new Test(); 
  Mug c1; 
  Mug c2; 
  { 
    c1 = new Mug(1); 
    c2 = new Mug(2); 
    System.out.println("c1 & c2 initialized"); 
  } 
  Mugs() { 
    System.out.println("Mugs()"); 
  } 
  public static void main(String[] args) { 
    System.out.println("Inside main()"); 
    Mugs x = new Mugs(); 
    monitor.expect(new String[] { 
      "Inside main()", 
      "Mug(1)", 
      "Mug(2)", 
      "c1 & c2 initialized", 
      "Mugs()" 
    }); 
  } 
} ///:~