ITPub博客

首页 > 应用开发 > Java > 浅谈 Java 中 this 的使用(转)

浅谈 Java 中 this 的使用(转)

原创 Java 作者:BSDLite 时间:2007-08-15 23:23:20 0 删除 编辑
浅谈 Java 中 this 的使用(转)[@more@]  1. this是指当前对象自己。

  当在一个类中要明确指出使用对象自己的的变量或函数时就应该加上this引用。如下面这个例子中:
CODE:
public class A {

String s = "Hello";

public A(String s) {
System.out.println("s = " + s);
System.out.println("1 -> this.s = " + this.s);
this.s = s;
System.out.println("2 -> this.s = " + this.s);
}

public static void main(String[] args) {
new A("HelloWorld!");
}
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10617542/viewspace-960353/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论