"Sampras", while you are waiting for an answer to your question, please take time to read our JavaRanch Naming Policy and change your displayed name to conform with it. In your case we need a name in the format <first name> <family name> (in that order). Thanks, -Barry [ April 18, 2005: Message edited by: Barry Gaunt ]
Hi, Your output is correct. In your for loop If i value is 0 then method getFoo() returns f ie.,Foo class reference. So its override superclass method react and print "Foo".
If I = 1 getFoo() method return subclass reference b and initialized into super class object f. So it override subclass method react() and display Bar.
If f=2 the getFoo() method returns reference f. but this time f has subclass refernce. bcoz it is initialized in for loop (ie, if I==1). so again and again it executes subclass method react().
So your output is exaclty correct
Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
As Nicholas pointed out we do require the form <first name> <family name>, not one name as you currently have.
The result "Foo Bar Foo Bar Foo Bar" can be obtained by replacing the use of the variable f by the variable f2 in the for-loop of the main method. So I guess someone got a little mixed up with what example when with which output.