class Person
{
static Person objRef = null;
int a, b;
private Person(int a,int b)
{
this.a = a;
this.b = b;
int[][] xx = new int[a][b];
for (int i = 0; i<xx.length ;i++ )
{
for (int j = 0; j<xx[i].length ; j++ )
{
xx[i][j] = j;
System.out.println("xx["+i+"]["+j+"]="+xx[i][j]);
}
}
}
public static Person getPerson()
{
if (objRef == null)
objRef = new Person(2,5);
return objRef;
}
}
class Study2
{
public static void main(String[] args)
{
Person p1 = Person.getPerson();
Person p2 = Person.getPerson();
System.out.println(p1==p2);
}
}如果我想在main中向构造函数传递数值要怎么做呢?前提不能改变单态设计模式.
{
static Person objRef = null;
int a, b;
private Person(int a,int b)
{
this.a = a;
this.b = b;
int[][] xx = new int[a][b];
for (int i = 0; i<xx.length ;i++ )
{
for (int j = 0; j<xx[i].length ; j++ )
{
xx[i][j] = j;
System.out.println("xx["+i+"]["+j+"]="+xx[i][j]);
}
}
}
public static Person getPerson()
{
if (objRef == null)
objRef = new Person(2,5);
return objRef;
}
}
class Study2
{
public static void main(String[] args)
{
Person p1 = Person.getPerson();
Person p2 = Person.getPerson();
System.out.println(p1==p2);
}
}如果我想在main中向构造函数传递数值要怎么做呢?前提不能改变单态设计模式.
class Person
{
static Person objRef = null;
int a, b;
private Person(int a,int b)
{
this.a = a;
this.b = b;
int[][] xx = new int[a][b];
for (int i = 0; i <xx.length ;i++ )
{
for (int j = 0; j <xx[i].length ; j++ )
{
xx[i][j] = j;
System.out.println("xx["+i+"]["+j+"]="+xx[i][j]);
}
}
}
public static Person getPerson(int x,int y)
{
if (objRef == null)
objRef = new Person(x,y);
return objRef;
}
}
public class Study2
{
public static void main(String[] args)
{
Person p1 = Person.getPerson(2,5);
Person p2 = Person.getPerson(2,5);
System.out.println(p1==p2);
}
}