class Single{
private String name;
private static Single s=new Single();
private Single(){}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public static Single getInstance(){
return s;
}
}
class SingleTest{
public static void main(String[] args){
Single s1=Single.getInstance();
s1.setName("AA");
Single s2=Single.getInstance();
s1.setName("BB");
System.out.println(s1.getName());
System.out.println(s2.getName());
}
}
|
|