This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have a method orThis(), which is present in class TopTier.
This method in inherited in class MiddleTier, when MiddleTier extends TopTier. Now in MddleTier class , I am overriding orThis(). But If I want to use the behavior of orThis() available in TopTier class, I can still use super.orThis() to invoke orThis available in TopTier class.
Now , I am creating BottomTier class, which extends MiddleTier class. And again orThis() is overridden in BottomTier class. Now if I use super.orThis() in BottomTier, will it call orThis() from MiddleTier class or TopTier class. I think it should call orThis() from MiddleTier as its immediate super class.
If this is true, then in the instance of a BottomTier class , how to invoke behavior of orThis() available in TopTier super class ?
I did not understand your reply.
If I want to invoke orThis() available in the TopTier class in the BottomTier class, how can I do this ?
BottomTier is sub class of MiddleTier, which in turn is subclass of TopTier. orThis() , which is in TopTier class is overridden in sub class MiddleTier and again orThis() is overriddden in BotomTier which is sub class of MiddleTier. I want to call orThis() in BottomTier class which is available in super class of super class.
But that may not always be an option. You are creating a new instance of a TopTier class, with new member variables. the values those are set to may not be the same...or it may change something in the newly created TopTier instance, when what you really need is changes to your BottomTier instance.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Dec 04, 2009
fred rosenberger wrote:But that may not always be an option. You are creating a new instance of a TopTier class, with new member variables. the values those are set to may not be the same...or it may change something in the newly created TopTier instance, when what you really need is changes to your BottomTier instance.
hey, its so simple. We make our BottomTier extend TopTier. Then call super.isThis().
But, again here we are compromising on the MiddleTier's methods. BottomTier wont be able to access MiddleTier's members.