| | |
Help with overriding methods
![]() |
•
•
Join Date: Apr 2005
Posts: 5
Reputation:
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
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:
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
Java Syntax (Toggle Plain Text)
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
Posts: 53
Reputation:
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
-------------------------------------------
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: Confusion with constructors
- Next Thread: I Need Help Please!
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class client code compile compiler component database developmenthelp eclipse error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loops mac main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying number online pearl problem program programming project qt recursion scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






