
this关键字的用法如下:
1、调用本类方法
public String introYourself() {
return this.whoAreU() + this.haoOldAreU();
}2、调用本类属性
public void changeMyName(String name) {
this.name = name;
}3、调用本类的其他构造方法
public UserExample(String name) {
this(name, -1);
}4、调用父类的或指定的其他的类的同名方法
public String whoAreSuper() {
return "super is " + UserExample.this.whoAreU() + ". ";
}5、隐藏式的调用,不指定范围,java会在全类范围内向上查找变量或方法
public String whoAmI() {
return whoAreU();
}推荐教程:Java教程
以上就是java中this关键字的几种用法的详细内容,
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)