• 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

get variable info from subclass

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my toString method that is in my linkedStackClass and you'll notice where it says size, well size will be entered in the gui portion of my code but how do I get my toString to see what size is equal to?

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am going to go out on a limb and assume this is related to your other thread from earlier today. This is one of those instances where recursion can be your friend. I whipped up the following example using your LinkedStackClass code in your other thread. (It's runnable but I had to slightly alter it to account for your other classes it references but which I do not have so it would compile. It no longer implements any interface and the StackUnderrunExceptions are now just plain Exception).



Notice I renamed your toString() to printStack(). Since you only get one shot at overriding toString(), is this really what you wanted to use it for?
As for how to get your toString() method to see the value of the size, well...the size variable would have to be an instance variable visible to the toString() method since you haven't declared any size variable local to the method.
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup that is correct. Well I might as well put the rest of my code out there. This is my DropOutStack Class maybe it would be easier to override the toString in here? I guess I'm kinda confused about some of the code you added and how it works like this part. return stackTop == null ? "" : stackTop.printStack();
 
Alex Hurtt
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dustin Schreader wrote:I guess I'm kinda confused about some of the code you added and how it works like this part. return stackTop == null ? "" : stackTop.printStack();



In more verbose code that would read:



If you examine your StackNode class you will see I added the method printStack() to it.
reply
    Bookmark Topic Watch Topic
  • New Topic