• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple super & this question

 
Claire Yang
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code, why super.i & super.s changed in method compare()?
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Claire
well, in test class we don't have another int i and String s defined right? so, we have ONLY ONE copy of variable i and variable s hence super.i = this.i for test object and super.s = this.s as well.
do u see what i mean?
super.i and this.i is just different mehtods of referring to same variable here (same for super.s and this.s)..
try ,
System.out.println(super.s == this.s ); in compare() method, it will return u "true" meaning both the String referrences are same...
regards
maulin
 
Claire Yang
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maulin,

I see what you mean, I forgot that I created 2 objects in the main method, thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic