JAVA this,
分享于 点击 30968 次 点评:86
JAVA this,
this引用:在非static方法和构造器中可以使用。在方法中this代表操作的是本对象,构造器中表示正在初始化的对象,用法:
public Apple
{
String name;
public Apple(String name)
{
this.name = name; //如写成name=name不能达到目的,this.name代表正在初始化的对象的name field。
}
}
this调用:只能在构造器的第一行使用。调用方法中其他的构造器:
public test(int a,int b)
{
//构造器内容
}
public test(int a,int b,int c)
{
this(a,b); //this调用上一个构造器
}
相关文章
- 暂无相关文章
用户点评