public int getNum()
{
return num;
}
private Single(){}
private static Single s=new Single();//这个是在方法区中,不再内存中
public static Single getSingle(s)//需要返回一个对象
{
return s;
}
}
class SingleDemo
{
public static void main(String[] args)
{
Single s1=Single.getSingle();
Single s2=Single.getSingle();
比如 int test() { return 1; } 该方法 返回值类型是int 返回的数就必须是一个整形数据 int x = test(); 相当于int x = 1;
static Test test(){ return new Test(); } 该方法返回值是Test类型 返回的是一个对象 对比上面 Test t = Test.test(); 相当于Test t = new Test();