Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Field of same name in subclass as superclass  RSS feed

Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • 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 noticed he had no friends. So we gave him this tiny ad:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!