A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© wyf20106 中级黑马   /  2014-8-10 17:50  /  6653 人查看  /  10 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 wyf20106 于 2014-8-10 23:19 编辑
  1. class  Person
  2. {
  3.         private String name;
  4.         private int age;

  5.          Person(String name)
  6.         {
  7.                 this.name = name;
  8.         }
  9.         Person(String name,int age)
  10.         {
  11.                 this.name = name;
  12.                  this.age = age;
  13.         }
  14.         public void speak()
  15.         {
  16.                 System.out.println("name="+this.name+"...age="+this.age);
  17.                 this.show();
  18.         }
  19.         public void show()
  20.         {
  21.                 System.out.println(this.name);
  22.         }
复制代码


10 个回复

倒序浏览
这里有篇博客,写的详细,你看看吧
http://blog.sina.com.cn/s/blog_6a6badc90100t8hm.html
回复 使用道具 举报
:Lthis 代表当前对象的引用,因为方法括号里的形参跟成员变量重名,所以要显式地用this来标识
回复 使用道具 举报
this是表示的当前的意思,程序从上向下执行,比如name的值改变了,貌似后面引用的this。name值就是最新值

点评

迷糊了  发表于 2014-8-10 18:42
回复 使用道具 举报
Joemi 发表于 2014-8-10 17:57
这里有篇博客,写的详细,你看看吧
http://blog.sina.com.cn/s/blog_6a6badc90100t8hm.html ...

嗯好的,谢谢
回复 使用道具 举报
dispensable 发表于 2014-8-10 18:01
this 代表当前对象的引用,因为方法括号里的形参跟成员变量重名,所以要显式地用this来标识 ...

嗯嗯 看懂了点。谢谢
回复 使用道具 举报
this表示对象的引用
回复 使用道具 举报
因为this是当前对象的引用,在本类中,用于区分重复的变量名
回复 使用道具 举报
你不写this他哪儿能分得出哪个是你传的参数,哪个是变量啊
回复 使用道具 举报
this表示代表这个类  this.num  就可以理解为 这个类的num变量
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马