Help with overriding methods

Reply

Join Date: Apr 2005
Posts: 5
Reputation: drunkpanda is an unknown quantity at this point 
Solved Threads: 0
drunkpanda drunkpanda is offline Offline
Newbie Poster

Help with overriding methods

 
0
  #1
Apr 4th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with overriding methods

 
0
  #2
Apr 4th, 2005
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 5
Reputation: drunkpanda is an unknown quantity at this point 
Solved Threads: 0
drunkpanda drunkpanda is offline Offline
Newbie Poster

Re: Help with overriding methods

 
0
  #3
Apr 4th, 2005
thank you Jwenting
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 4
Reputation: khoomy is an unknown quantity at this point 
Solved Threads: 0
khoomy khoomy is offline Offline
Newbie Poster

Re: Help with overriding methods

 
0
  #4
Apr 5th, 2005
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;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 5
Reputation: drunkpanda is an unknown quantity at this point 
Solved Threads: 0
drunkpanda drunkpanda is offline Offline
Newbie Poster

Re: Help with overriding methods

 
0
  #5
Apr 5th, 2005
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

  1. public String toString()
  2. {
  3. String thePlayer = currentPlayer.getName();
  4. return thePlayer;
  5. }

for example:
System.out.println(toString()); //which display player's name
System.out.println(somthing else);

Drunkpanda
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 53
Reputation: aj.wh.ca is an unknown quantity at this point 
Solved Threads: 1
aj.wh.ca aj.wh.ca is offline Offline
Junior Poster in Training

Re: Help with overriding methods

 
0
  #6
Apr 6th, 2005
Where do you get mutiple Strings ? Not clear with your example.
cheers,
aj.wh.ca

-------------------------------------------
www.swiftthoughts.com
-------------------------------------------
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC