• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Field of same name in subclass as superclass

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I was reading this book, and came across this code regarding the Singleton class, and extending this class:



As you can see, the uniqueInstance variable is present in both classes.
Obviously we need it in the superclass, but why is it present in the subclass?
I did a little test, and it seems they are equal.
Is this just for clarity? What generally happens with variables of the same name in a superclass and subclass?

Thanks for any info.

I've just re-read the post, and noticed the uniqueInstance gets sets to the type of the superclass, so surely this won't work since we want a CoolerSingleton object stored there?
[ May 14, 2007: Message edited by: colin shuker ]
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic