Nother
程序员,规则的,陈述者! Programmer is Representor Of Rules!
this的另一用法
This 的另一个用法,就是构造函数的第一个语句,它的形式是this(参数表),这个构造函数就会调用同一个类的另一个相对的构造函数。
thisdemo
public
class
ThisDemo
{
int
var;
ThisDemo(
double
var)
{
this
.var
=
(
int
)var;
}
ThisDemo(
int
var)
{
this
(
"
hello
"
);
}
ThisDemo(String str)
{
this
();
System.out.println(str);
}
ThisDemo()
{
System.out.println(
"
World
"
);
}
public
static
void
main(String args[])
{
ThisDemo td
=
new
ThisDemo(
5
);
}
}
程序运行结果:
World
hello
posted on
2008-07-30 00:20
哪热
阅读(105) 评论(
2
)
编辑
收藏
刷新评论
刷新页面
返回顶部
程序员问答社区,解决您的IT难题
博客园首页
博问
新闻
闪存
程序员招聘
知识库
Powered by:
博客园
Copyright © 哪热
导航
博客园
首页
新随笔
联系
订阅
管理
统计
随笔 - 62
文章 - 0
评论 - 73
引用 - 0
公告