正在加载图片...
How instance method works? Person a=new Person(),b=new Persion(); a.setWeight(100);b.setWeight(120); D How can the method know whether it's been called for object a or b? OInternal:Person.setWeight(a,100); o Invisible additional parameter to all instance methods:this o It holds a reference to the object through which the method is invoked Oa.setWeight(100)>this=aHow instance method works? lHow can the method know whether it’s been called for object a or b? ¡Internal: Person.setWeight(a, 100); lInvisible additional parameter to all instance methods: this lIt holds a reference to the object through which the method is invoked ¡a.setWeight(100)  this=a Person a=new Person(), b=new Persion(); a.setWeight(100); b.setWeight(120);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有