Hi Friend, Can someone please explain me how the flow of the following program works.I thought any expression of the form :"((X)this).hiddenfield" would access the X's (class or interface) hidden field.So,I1's m1() method should be called causing no output.
You're asking about hidden fields, but your example uses overridden methods. These are very different.
Here's what's happening in your example code: You do not have a hidden field. Instead, you have an overridden method. The instance of TestClass is upcast to type I1. But when the method m1 is called, polymorphism invokes the method definition in TestClass, where m1 is implemented.
Now, here's what I think you're asking about: Suppose you had also defined the field VALUE in TestClass, then upcast your instance of TestCode to type I1 (in which VALUE is also defined). Now you have a hidden field, as illustrated in the code below.
To see the significance of this, look what happens when an overridden method tries to access the field...
[ May 18, 2005: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org