无语。接连发了2篇都夭折了。辛苦码了那么多字。算了,直接从第3章开始了。
Initialization
关于构造器:
class Rock {
Rock() {
System.out.print("Rock ");
}
}
public class SimpleConstructor {
public static void main(String[] args) {
for(int i=0;i<10;i++)
new Rock(); // 很明显对象被创建的时候,访问构造器。
}
}
可以看出来构造器就是一种特殊的方法。方法名规定必须用类名。首字母大写。无返回值。在new的时候被访问。其作用是为了初始化。
关于this,produces the reference to the object that the method has been called for.