• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ServerLocation@4554617c

 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,



My ServerLocation.java

OUTPUT:
=======
IR
Iran, Islamic Republic of
Country is: ServerLocation@4554617c

Please advise why this ServerLocation@4554617c is printed always

Best regards
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because you haven't overwritten toString(), and that's what toString() returns if it's inherited from java.lang.Object: the class name followed by an @ and the hexadecimal representation of the hash code.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply

Can you please refer me any code example?

Best regards
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Farakh khan wrote:


You are missing things here. Your class ServerLocation isn't even storing the values that you pass to the setter methods - it just prints the values and forgets about them.

You need to add member variables to the class, and in the setter methods set the values of the member variables.

You also need to implement a toString() method in the class, otherwise you get output such as "ServerLocation@4554617c" when you try to print a ServerLocation object.

(Click the links for more information).
reply
    Bookmark Topic Watch Topic
  • New Topic