Author | Message |
---|---|
knagrec2
Posts: 51
|
Posted 10:27 Oct 02, 2018 |
toString does not really need to format anything, it essentially just needs to print the question. Because toString() is an override, it must have the return type String. So then what is the difference between toString and getQuestion, if they both essentially are just returning the questionText? What is the point of toString()? |
rgallegos
Posts: 29
|
Posted 00:09 Oct 03, 2018 |
Any time you have your object/class printing something in a particular format you want to overwrite the toString because if you don't Java will give you a default and it won't be the one you're expecting. In Java every class is an Object and every Object has a toString. Depending on how you wrote your program you can just have your toSting method call your question text. |