中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > JSP > 综合文章
JavaConstructor
作者:佚名 时间:2005-04-13 11:12 出处:互连网 责编:chinaitpower
              摘要:JavaConstructor
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 (子类)


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有