J2ME平台A-RPG游戏怪物寻路算法初探

<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog01.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>

class Singleton {


private static Singleton obj = new Singleton();

public static int counter1;

public static int counter2 = 0;

private Singleton() {
counter1++;
counter2++;
System.out.println("constructor counter2's value :"+counter2);
}

public static Singleton getInstance() {
System.out.println("getInstance counter2's value :"+counter2);
return obj;
}
}

public class MyMain {

@SuppressWarnings("static-access")

public static void main(String[] args) {

Singleton obj = Singleton.getInstance();
System.out.println("obj.counter1=" + obj.counter1);
System.out.println("obj.counter2=" + obj.counter2);

Singleton obj1 = Singleton.getInstance();
System.out.println("obj1.counter1=" + obj1.counter1);
System.out.println("obj1.counter2=" + obj1.counter2);
}
}

输出结果是:

obj.counter1=1
obj.counter2=0
obj1.counter1=1
obj1.counter2=0



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1392662


你可能感兴趣的:(游戏,.net,算法,Blog,Access)