Login Register






interfaces help filter_list
Author
Message
RE: interfaces help #41
(11-27-2013, 02:29 PM)Deque Wrote: @blackeagle:

(11-27-2013, 02:07 AM)darthjames226 Wrote: The toString() returns a string equivalent. For example:

int value = 30;
System.out.println(value.toString());

This code snippet would print out 30. Notice that value will be displayed as a String and not as an integer.

This code snippet is wrong and the problems above actually came from your example. If you provide snippets to programming beginners, make sure they are working and do not create more problems than helping.

(11-27-2013, 03:36 AM)darthjames226 Wrote: Only thing I can see that could be wrong is this:
@Override
public String toString(){
return name;

return purchasePrice.toString(); //calls your override method
return salePrice.toString(): //uses colon instead of semicolon
//calls your override method


}

You used a colon instead of a semicolon on your last statement. Since you did a override on toString(), you are calling your method on the statements inside of your method.

Don't override toString(). Change its name to something else and try to compile. That will let you know if that's the problem.

That is nonsense.


Sorry about that. My value variable should have been declared as type Integer instead of int in my code snippet. The second explanation under that original post was perfectly fine. As for all the advice I provided, I am no pro Java programmer. I was just trying to help a fellow programmer troubleshoot a bug in his program at a time of need. No one else was trying to help him so I took the initiative and intervened. If my advice is wrong then let me know so I can learn from my mistakes. I was simply trying to help.

Reply





Messages In This Thread
interfaces help - by blackeagle - 11-25-2013, 11:51 PM
interfaces help - by blackeagle - 11-25-2013, 11:51 PM