第1个回答 2009-11-24
public class Text {
static int instanceCount = 0;
Text() {
instanceCount++;
if(instanceCount > 3) {
try {
throw new TextException();
} catch(Exception e) {
System.out.println("这个类已经实例化超过3次");
}
}
}
public static void main(String args[]) {
Text t = new Text();
Text t1 = new Text();
Text t2 = new Text();
}
}
class TextException extends Exception {}