首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

据说是每个菜鸟都无法给出输出结果的,特无耻的面试题

2012-12-28 
据说是每个初学者都无法给出输出结果的,特无耻的面试题请给出下面程序的输出结果:public class ClassLoade

据说是每个初学者都无法给出输出结果的,特无耻的面试题
请给出下面程序的输出结果:



public class ClassLoaderSeq {



/**

* @param args

*/

public static void main(String[] args) {

Singleton singleton = Singleton.getInstance();



System.out.println("counter1 = " + singleton.counter1);

System.out.println("counter2 = " + singleton.counter2);

}



}



public class Singleton {



private static Singleton singleton = new Singleton();

public static int counter1;

public static int counter2 = 0;



private Singleton(){

this.counter1++;

this.counter2++;

}



public static Singleton getInstance(){

return singleton;

}

}



这个让人纠结的输出结果:

counter1 = 1

counter2 = 0




热点排行