您的位置:首页 > 编程语言 > Java开发

java中this这个概念初学者非常难理解,请举例说明

2014-08-08 15:15 369 查看
继上一小节,(3.一个对象可能有多个参考)this是n多个参考当中的一个参考,是系统赋予的,与生俱来的,当对象产生了以后就自动具有了this这个参考了!this这个对象指向他自己。Any object has a “this” reference which refer to itself. So, You can use this reference to refer to the current object.

class MyTestDate {

int year;

int month;

MyTestDate(int year, int month, int day) {

this.year = year;//this.year指前面类范围的变量 int year。

this.month = month;

}

void setYear(int year) {

this.year = year;

}

void setMonth(int month) {

this.month = month;

}

public String toString() {

return "" + year + "/" + month ;

}

}

public class Test {

public static void main(String[] args) {

MyTestDate date = new MyTestDate(2009, 7, 18);

。。。。。。。。。。。。。。。。

详情请见:

http://www.mark-to-win.com/JavaBeginner/JavaBeginner2_web.html#This
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: