Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1819 | Replies: 5
![]() |
•
•
Join Date: Apr 2005
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
hi everyone
System.out.println(currentPlayer);
it returns to me like this:Player@7cbde6
i know it was caused by toString() and it is suggested to ues overriding method
but i don't know how to do it, so can somebody teach me how to use overiding method so System.out.println(currentPlayer); will display what i want
thank you very very much
drunkpanda
System.out.println(currentPlayer);
it returns to me like this:Player@7cbde6
i know it was caused by toString() and it is suggested to ues overriding method
but i don't know how to do it, so can somebody teach me how to use overiding method so System.out.println(currentPlayer); will display what i want
thank you very very much
drunkpanda
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation:
Rep Power: 19
Solved Threads: 200
What's the signature of toString?
All you need to do is provide a method with that exact signature in your own class.
By reading the API docs for java.lang.Object you can find out the signature of toString.
All you need to do is provide a method with that exact signature in your own class.
By reading the API docs for java.lang.Object you can find out the signature of toString.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Apr 2005
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Hi khoomy thanks
I have actually done something like this which works ok but what happen if i get mutiple String want to display each individually
for example:
System.out.println(toString()); //which display player's name
System.out.println(somthing else);
Drunkpanda
I have actually done something like this which works ok but what happen if i get mutiple String want to display each individually
public String toString()
{
String thePlayer = currentPlayer.getName();
return thePlayer;
}for example:
System.out.println(toString()); //which display player's name
System.out.println(somthing else);
Drunkpanda
•
•
Join Date: Mar 2005
Location: Woodland Hills CA
Posts: 49
Reputation:
Rep Power: 4
Solved Threads: 1
Where do you get mutiple Strings ? Not clear with your example.
cheers,
aj.wh.ca
-------------------------------------------
www.swiftthoughts.com
-------------------------------------------
aj.wh.ca
-------------------------------------------
www.swiftthoughts.com
-------------------------------------------
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode