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

为什么编译时会出非法向前引用的异常

2012-04-22 
为什么编译时会出非法向前引用的错误classCat{publicStringnamepublicintagepublicCat(Stringname,intag

为什么编译时会出非法向前引用的错误
class   Cat{
  public   String   name;
  public   int   age;
 
  public   Cat(String   name,int   age){
 
    System.out.println( "Constructor ");
    this.name   =   name;
    this.age   =   age;
  }
 
{
    System.out.println( "non-static   initial   block ");
      //   这边为什么不报向前引用的错误
      weight   =   2.0;
                  //   注释下面的语句编译可以通过
[color=#FF0000]System.out.println(weight);[/color]   }
  double   weight   =2.3   ;
  public   String   toString(){
    return   "Cat[name= "   +   name   + "   ,age=   "   +   age     + "   ,weight=   "   +   weight;
  }
}


public   class   InitTest{
  public   static   void   main(String[]   args){
    Cat   cat   =   new   Cat( "kitty ",2);
    System.out.println(cat);
    Cat   c2   =   new   Cat( "Jefi ",3);
    System.out.println(c2);
  }
}


[解决办法]
这是JAVA代码块
http://blog.csdn.net/lichaohn/article/details/5359240

热点排行
Bad Request.