|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
Java Constructor - constructor definition (not authority):A method that creates an object. In the Java, constructors are instance methods with the same name as their class.It can only have accessibility modifiers,no return value. - 每个class都必须有自己的constructor,它不能从父类中inherited.一个class可以有多个,但至少有一个, 假如没有显示声明构造函数,compiler会提供一个默认的不带参数的构造函数,注重的事,只要有一个显示 声明的constructor,将不会提供default constructor. - constructor 不可以有返回值,假如有返回值将会被视为一个普通的方式,不过与类同名。但是在constructor 里可以写return语句,public A(){return;} 是答应的。 - 在子类调用其constructor的时候,compliler会自动为其加上super();所以假如父类中没有显示的申明不带 参的构造函数,将会有编译错误。 - 在constructor里可以用this()/super()调用自己/父类中的其他构造函数,调用自己会有recursive invocation error.注重的是,this();或者super()都必须写在其第一句话,所以,this();和super();显然不能同时被调用。 - constructor initialization: 1.static variables (父类在前,子类在后,假如都有的话) 2.static initializer blocks (mutiple的情况按照申明先后执行,父类在前,子类在后) 3.instance variables,instance initializer blocks (父类) 4.constructor (父类) 5.instance variables,instance initializer blocks (子类) 6.constructor (子类) 返回类别: 教程 上一教程: 在Struts中使用JavaBean和List(多行数据)类型属性 下一教程: js中判定由字符串from和to代表的两个日期的先后关系 您可以阅读与"Java Constructor"相关的教程: · java与c/c++进行socket通信的一些问题(1) · JAVA的类和方式(教程) · JAVA在LINUX下的WEB应用(二) · Java中利用JMF编写摄像头拍照程序 · 在Java中如何模仿多继续 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |