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

下面这段程序中的this.number=number;   
          this.name=name;
表示什么啊?我删去了也可以得到同样的运行结果,为什么要加这两句?不太明白,望高手指教....
  1. class Student

  2.    { int number;String name;

  3.       Student()

  4.       {

  5.       }

  6.       Student(int number,String name)

  7.       { this.number=number;   
  8.           this.name=name;

  9.           System.out.println("I am "+name+ "my number is "+number);

  10.         }

  11. }
  12.        class UniverStudent extends Student

  13.        {    boolean 婚否;

  14.              UniverStudent(int number,String name,boolean b)

  15.               { super(number,name);

  16.                    婚否=b;

  17.                    System.out.println("婚否="+婚否);

  18.                 }

  19.         }

  20. public class Super1

  21. { public static void main(String args[])

  22. { UniverStudent zhang=new UniverStudent(1234,"hebinho",false);

  23.     }

  24. }
复制代码

4 个回复

倒序浏览
我记得老师是这讲的,谁调用这个this,我这个this就是谁,这句话我也是不明白,还是求大神们来个比较接地气的解析,小生就会感激不尽
回复 使用道具 举报
你没有删除this.number=number;    this.name=name;这两句的时候,打印的是类中成员属性的值,但是你删除后,打印的就是Student构造方法中的局部变量了。所以结果就是一样的
回复 使用道具 举报
比如:    Student  a = new Student();   this就是a    Student b = new Student(); this 就是b
回复 使用道具 举报
好好再看几遍视频就记住了:loveliness:
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马