Chinaunix首页 | 论坛 | 博客
  • 博客访问: 593337
  • 博文数量: 110
  • 博客积分: 8016
  • 博客等级: 中将
  • 技术积分: 1217
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-28 10:14
文章分类

全部博文(110)

文章存档

2008年(1)

2007年(13)

2006年(96)

我的朋友

分类: Java

2006-06-29 12:26:25

//c4:Constructor1.java

//author:ZhangHongbin

//This program is protected by copyright laws.

//Call constructor within another constructor. 

public class Constructor1

{

       Constructor1()

       {

              //this(7f);//error!

              this(5,7f);

       }

       Constructor1(float f)

       {

              System.out.println();

              System.out.println("f="+f);

       }

       Constructor1(int i,float f)

       {

              //System.out.println();//error

              this(f);

              System.out.println("i="+i);

              System.out.println("i+f="+(f+i));

       }

       public static void main(String[] args)

       {

              Constructor1 object1=new Constructor1();

       }

}

/**

this代表"这个对象",super代表"这个对象"的超类。

 

在一个构造方法中只能调用一次其他的构造方法。并且调用构造方法的语句是第一条语句。

*/

 

阅读(1173) | 评论(0) | 转发(0) |
0

上一篇:JAVA静态块和非静态块

下一篇:存取控制符

给主人留下些什么吧!~~