RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1819 | Replies: 5
Reply
Join Date: Apr 2005
Posts: 5
Reputation: drunkpanda is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
drunkpanda drunkpanda is offline Offline
Newbie Poster

Help with overriding methods

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with overriding methods

  #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  
Join Date: Apr 2005
Posts: 5
Reputation: drunkpanda is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
drunkpanda drunkpanda is offline Offline
Newbie Poster

Re: Help with overriding methods

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

Re: Help with overriding methods

  #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  
Join Date: Apr 2005
Posts: 5
Reputation: drunkpanda is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
drunkpanda drunkpanda is offline Offline
Newbie Poster

Re: Help with overriding methods

  #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

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
Reply With Quote  
Join Date: Mar 2005
Location: Woodland Hills CA
Posts: 49
Reputation: aj.wh.ca is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
aj.wh.ca aj.wh.ca is offline Offline
Light Poster

Re: Help with overriding methods

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:40 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC