Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

JQPlus Doubt

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
That is a really big piece of pie for such a tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!