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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王裕秋 中级黑马   /  2013-11-1 21:37  /  1169 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 王裕秋 于 2013-11-1 21:45 编辑

class Person
{
        private String name;
        private int age;
        Person(String name,int age)
        {
                this name = name;
                this age  = age;
        }
        public String getName()
        {
                return name;
        }
        public int getAge()
        {
                return age;
        }

}
这个类写出来,this  name =name那句说this不是语句,求教

6 个回复

倒序浏览
是this.name不是this name
回复 使用道具 举报
this.name,this是指向堆那边函数所在对象的引用
回复 使用道具 举报

                this.name = name;
                this.age  = age;
应该是这样,你少了个点。
回复 使用道具 举报
应该是this.name=name;关于这个this的含义,this代表本类对象,此处代表Person的实例化对象
回复 使用道具 举报
楼上也说了,应该是this.name=name;

关于this,理解成哪个对象调用这个this所在函数,this就代表那个对象。
回复 使用道具 举报
class Person
{
        private String name;
        private int age;
        Person(String name,int age)
        {
                this.name = name;
                this.age  = age;             //tihis.age     this后边有点
        }
        public String getName()
        {
                return name;
        }
        public int getAge()
        {
                return age;
        }

}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马