think in java中有一处讲到尽管没有“显式地使用static关键字,构造器实际上也是静态方法。”
但是静态方法不是不能对非静态字段进行引用的吗?
但是我试过了好像可以呀。
这是为什么呢?
code:class StaticArea{
int i;
StaticArea(){
i=3;
}
}
public class TestStatic {
public static void main(String[] args){
StaticArea sa=new StaticArea();
System.out.println(sa.i);
}
}求解释...

解决方案 »

  1.   

    显式地使用static关键字,构造器实际上也是静态方法
    你的static在哪?
      

  2.   

    你new 的 啊 当然没有问题了
      

  3.   

    尽管没有显式地使用static关键字,构造器实际上也是静态方法
    主要看后面的描述,其实和说private methods是final的那段一样,都是说的意义,而不是结构
    So the first time an object of type Dog is created, or the first time astatic method or static field of class Dog is accessed, the Java interpreter mustlocate Dog.class, which it does by searching through the classpath.
      

  4.   

    thinking in java这地方很扯淡
      

  5.   

    是啊,在Douglas的《Java Rules》里面明确地写了构造器是非static的,看来他们2个需要一次很好的交流