my dog learned polymorphism*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "simple super & this question" Watch "simple super & this question" New topic
Author

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: 1871
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

Joined: Aug 30, 2002
Posts: 57
Maulin,

I see what you mean, I forgot that I created 2 objects in the main method, thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple super & this question
 
Similar Threads
code
Doubt about Array
Inheritance
use of super -Examlab Question
super reference nor referring to the super class Examlab Test no 2 question 2