using System;
class A
{
public static void Main(String [] args)
{
B m = B.GetB();
m.j=100; //make changes to instance variable j
Console.WriteLine(m.j);
B x = B.GetB(); //x.j print's 100 which means that there is one and only one Instance
Console.WriteLine(x.j); }
}class B
{
private static B x;
public int j= 0;
private B()
{
}
public static B GetB()
{
if(x==null)
{
x=new B();
}
return x;
}
}
class A
{
public static void Main(String [] args)
{
B m = B.GetB();
m.j=100; //make changes to instance variable j
Console.WriteLine(m.j);
B x = B.GetB(); //x.j print's 100 which means that there is one and only one Instance
Console.WriteLine(x.j); }
}class B
{
private static B x;
public int j= 0;
private B()
{
}
public static B GetB()
{
if(x==null)
{
x=new B();
}
return x;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货