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

4
Contributors
5
Replies
6
Views
12 Years
Discussion Span
Last Post by aj.wh.ca
0

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.

0

hellow,
all u hv to do is that override toString() method as one friend also told it, its signature is

public String toString(){
String str;
str = "any thing you want do it here, and place this method in ur class";
return str;
}

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.