permaculture playing cards
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes simple super & this question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "simple super & this question" Watch "simple super & this question" New topic

simple super & this question

Claire Yang
Ranch Hand

Joined: Aug 30, 2002
Posts: 57
In the following code, why super.i & super.s changed in method compare()?
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
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...
Claire Yang
Ranch Hand

Joined: Aug 30, 2002
Posts: 57

I see what you mean, I forgot that I created 2 objects in the main method, thanks a lot.
It is sorta covered in the JavaRanch Style Guide.
subject: simple super & this question
It's not a secret anymore!