sos

class Bowl {
  Bowl(int er) 
  {
    System.out.println("Bowl(" + er + ")");
  }
  void f(int er) 
  {
    System.out.println("f(" + er + ")");
  }
}class Table 
{
  static Bowl b1 = new Bowl(1);
  Table() 
  {
    System.out.println("Table()");
    b2.f(1);
  }
  void f2(int er) 
  {
    System.out.println("f2(" + er + ")");
  }
  static Bowl b2 = new Bowl(2);
}class Cupboard 
{
  Bowl b3 = new Bowl(3);
  static Bowl b4 = new Bowl(4);
  Cupboard() 
  {
    System.out.println("Cupboard()");
    b4.f(2);
  }
  void f3(int er) 
  {
    System.out.println("f3(" + er + ")");
  }
  static Bowl b5 = new Bowl(5);
}public class StaticInitialization 
{
  public static void main(String[] args) 
  {
    System.out.println("Creating new Cupboard() in main");
    new Cupboard();
    System.out.println("Creating new Cupboard() in main");   
    new Cupboard();
    t2.f2(1);
    t3.f3(1);
  }
  static Table t2 = new Table();
  static Cupboard t3 = new Cupboard();
}
输出结果:
Bowl(1)
Bowl(2)
Table()
f(1)
Bowl(4)
Bowl(5)
Bowl(3)
Cupboard()
f(2)
Creating new Cupboard() in main
Bowl(3)
Cupboard()
f(2)
Creating new Cupboard() in main
Bowl(3)
Cupboard()
f(2)
f2(1)
f3(1)
本人自学JAVA,现在是菜鸟级别,希望高人解释一下这个程序

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【Chaneo6】截止到2008-07-18 23:22:12的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:18                       得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:1                        结贴的总分数:0                        
    无满意结贴数:1                        无满意结贴分:20                       
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:---------------------
    无满意结贴率:100.00%               无满意结分率:---------------------
    敬礼!
      

  2.   

    这道题是主要是说明程序优先级,先进行静态初始化。比如程序一开始是先进行  static Table t2 = new Table();