The java ranch question #20: Can a private method of a superclass be declared within a subclass? Java Ranch Answer: Yes "Trick question! Private methods can NOT be overridden, but they can be redeclared/redefined in the subclass, and called directly on the subclass object. But polymorphism will not apply" Kathy and Bert Book on Objective 1.2 Private Members page 74, second and third paragraph: "A private member is invisible to any code outside the member's own class...When a member is declared private, a subclass can't inherit it." Maybe a better question is: "Can a method with the same name as a private superclass method be declared in a subclass?"
But heck, that would give it away . The real exam will word it that it can not be inherited, but that it can be declared. I think that both are fine the way that they are worded. Actually we have discussed the wording of that concept several time in detail and this is the way that it was decided on.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Actually we have discussed the wording of that concept several time in detail and this is the way that it was decided on. Got a link? Seems to me Leo's right - the wording we have just doesn't make sense. "Can a private method of a superclass be declared within a subclass?" No, but we can declare a new method with the same signature. that would give it away As opposed to obfuscating the answer with self-contradictory terminology?
"I'm not back." - Bill Harding, Twister
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad: