think in java96页上说即使没有显示的使用static关键字,构造器实际上也是构造方法。但是我觉得为什么构造器还可以用this,还可以访问成员变量。
新手发帖,求高手解答

解决方案 »

  1.   

     constructor 就是一个特殊的没有返回类型的method
      

  2.   

    但是书上怎么说是不加static的静态方法,难道错么吗
      

  3.   

    调用机制决定的,那你说为什么main就入口,我其他函数不行
      

  4.   

    但是他为什么还可以用this呢,不是静态函数不能用吗
      

  5.   

    不知道是翻译的问题还是你断章理解的问题静态方法和构造方法意义和作用不同,而且使用方式也不同。--你自己可以比较一下等到你使用java一段时间后就明白了
      

  6.   

    这可是think in java,不知道他为什么这么说
      

  7.   

    The constructor is an unusual type of method because it has no return value. This is distinctly different from a void return value, in which the method returns nothing but you still have the option to make it return something else. --原文
      

  8.   

    看这篇jvm大牛的博客:http://rednaxelafx.iteye.com/blog/652719
      

  9.   

    Even though it doesn't explicitly use the static keyword, the constructor is actually a static method. So the first time an object of type Dog is created, or the first time a static method or static field of class Dog is accessed, the Java interpreter must locate Dog.class, which it does by searching through the classpath. 《java编程思想》中文第四版96页: 翻译如下:总结一下对象的创建过程,假设有个名为Dog的类: 1.即使没有显示地使用static关键字,构造器实际上也是静态方法。因此,当首次创建类型为Dog的对象时(构造器可以看成 是静态方法),或者Dog类的静态方法/静态域首次被访问时,Java解释器必须查找类路径,以定位Dog.class文件
      

  10.   

    这个答案比《thinking in java》的作者权威多了,没人信?