package
com.test;
public
class
MainTest {
public
static
void
main(String[] args) {
SingletonsTest
test = SingletonsTest.getInstance();
SingletonsTest
test2 = SingletonsTest.getInstance();
// SingletonTest
tss
= new SingletonTest();
}
}
class
SingletonsTest{
private
static
SingletonsTest uniqTest;
private
SingletonsTest(){
}
public
static
synchronized
SingletonsTest getInstance(){
if(uniqTest
== null){
System.out.println("New
instances are created====");
uniqTest
= new
SingletonsTest();
}
return
uniqTest;
}
}
No comments:
Post a Comment