This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm trying to get the default toString method overridden by my version. However, it's not even getting called by main. Why? Do all overridding methods have to be public? I can't make it public since the driving class containing main (is in the same file) and must be public. Any help would be deeply appreciated. Here's the code:
[This message has been edited by Cindy Glass (edited December 19, 2001).]
Overriding methods do not have to be public, but they can not be more restrictive than the method they are overriding. In other words, if the method is public, you can't override it making it protected, default, or private. In regards to your program, your output should look something like Str in ButtonTest = ButtonTest@17d275 This is correct for the program you have written. ButtonTest is not overriding toString(), your Stack class is. Since you never create an object of Stack, that toString() method is not called. Since ButtonTest doesn't override toString(), Object's implementation is called, which simply returns the hashcode of that object. Jason [This message has been edited by jason adam (edited December 19, 2001).]
hi, are you overriding the method toString() of ButtonTest ? as i see it, you only override it in the class Stack. but you only construct a ButtonTest, no Stack. you ned either construct a Stack object or override the toString() method in the ButtonTest class. karl