养女皇后周小史结局:java类拦截方法是甚么?

来源:百度文库 编辑:中科新闻网 时间:2024/07/04 19:02:08

不知道你所说的是不是Singleton模式?
单态模式保证一个类只有一个实例如:
class TestSingleton
{
private static TestSingleton instance=new TestSingleton();

private TestSingleton()
{
System.out.println("only one instance.");
}

public static TestSingleton getInstance()
{
return instance;
}

}
class Main
{

public static void main(String[]args)
{
TestSingleton.getInstance();
TestSingleton.getInstance();
//new TestSingleton();
}
}