• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overiding Java toString method  RSS feed

 
benjamin parker
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i print overide the toString for WebBrowser as i would like to print out the object bc. Tested the program and it is fine if i put it in the main method rather than the WebBrowser constructor.

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean. You can just add a toString() method to your class WebBrowser.

What do you mean with "it is fine if i put it in the main method rather than the WebBrowser constructor" - if you put what exactly in the main method rather than the WebBrowser constructor?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
benjamin parker wrote:How do i print overide the toString for WebBrowser as i would like to print out the object bc.

Like Jesper, I'm completely mystified as to what your problem is, so back up and TellTheDetails (←click).

You're also not helping yourself by using cryptic names like 'bc'. It may mean something to you, but it certainly doesn't to us.

All I see so far is a class called WebBrowser that takes lines from a Scanner, encoded according to rules that you haven't explained to us, that loads a linked list that you've rolled yourself.

My advice: Deal with one thing at a time.

If you want to write a Lynx-like web browser - which is a formidable enough task just by itself - don't compound it by re-inventing the wheel. Java already has a perfectly good linked list class (called, strangely enough, LinkedList; which might also cause you problems unless you're very careful), which has been thoroughly tried and tested, so you don't need to.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!