How to create your class can only be instance once

Kamis, Maret 23, 2006
Try some of this code out!

public class Test {
private static boolean status=false; //before instance

Test() {
if (status) {
System.out.println("Only once instance only");
System.exit(1);
}else {
status = true; //instance for the first time
System.out.println("Object is instance");
}
}

public static void main(String [] args)
{
Test t1 = new Test();
Test t2 = new Test(); //this will make some effect see by yourself ^^
}
}

0 komentar: