java的单例实现

class SingLeton 
{
	//单例的实现
	private static SingLeton instance;
	private SingLeton(){
	}
    
	public static SingLeton getSingLeton(){
	
	  if(instance==null){
	     instance= new SingLeton();
	  }
	  return instance;
	}

	
}

public class TestSingLeton
{
	public static void main(String[] args) 
	{
		SingLeton s1=SingLeton.getSingLeton();
        SingLeton s2=SingLeton.getSingLeton();

		System.out.println(s1==s2);
		System.out.println(s1.equals(s2));
	}
}

你可能感兴趣的:(java)