• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JQPlus Doubt

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks in Advance.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic