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
posted 14 years ago
Thanks Marc, You are right...probably i was mixing overriding methods with the concepts of hidden fields.But,after goin thru your post and running that code ...everything stands crystal clear. Thanks
SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
That is a really big piece of pie for such a tiny ad:
create, convert, edit or print DOC and DOCX in Java