重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

浅谈Java中this的使用(转)

浅谈 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!");
}
}

网站名称:浅谈Java中this的使用(转)
浏览路径:http://cqcxhl.cn/article/jjjhdp.html