package com.sun.spring.mvchello;
public class Singelton {
private static Singelton singletonInstance;
private Singelton(){
}
public static Singelton getInstance(){
if(singletonInstance == null){
singletonInstance = new Singelton();
}
return singletonInstance;
}
}
public class Singelton {
private static Singelton singletonInstance;
private Singelton(){
}
public static Singelton getInstance(){
if(singletonInstance == null){
singletonInstance = new Singelton();
}
return singletonInstance;
}
}
package com.sun.spring.mvchello;
/**
* Hello world!
*
*/
public class App
{
public static void main(String args[]){
Singelton singelton1 = Singelton.getInstance();
Singelton singelton2 = Singelton.getInstance();
System.out.println("Singelton1"+singelton1);
System.out.println("Singelton2"+singelton2);
System.out.println("=="+(singelton1 == singelton2));
System.out.println("equals"+singelton1.equals(singelton2));
}
}
No comments:
Post a Comment