• Post Reply Bookmark Topic Watch Topic
  • New Topic

Making the array print clear english?  RSS feed

 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have my code here but whenever i print, a part of the print is showing up in an unreadable format. any help as to what i need to do?



prints:

Fred 21
Jo 43
Harry 78
Zoe 37
[Data@1540e19d, Data@677327b6, Data@14ae5a5, Data@7f31245a]
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When you try to print any object, that is not a string, the println() method will call the toString() method of the object, in order to get the string representation, so that it can print it.

Since your Data class, did not implement the toString() method, it will inherit it from its super class. And with the Object class, the toString() method returns the name of the class along with the Identity hash for the instance.

Henry
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
When you try to print any object, that is not a string, the println() method will call the toString() method of the object, in order to get the string representation, so that it can print it.

Since your Data class, did not implement the toString() method, it will inherit it from its super class. And with the Object class, the toString() method returns the name of the class along with the Identity hash for the instance.

Henry



Would this be more appropriate?

 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
orry kaplan wrote:Would this be more appropriate?

Did you compile and run this code? what does this print?
  • Method name getName and getAge woould look better rather than GetName and GetAge.
  • Posting complete code would definitely increase the chances of getting answer.
  •  
    Campbell Ritchie
    Marshal
    Posts: 55772
    163
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    orry kaplan wrote:. . . Would this be more appropriate? . . .
    No. Deciding what to print shou‍ld be a task done inside the class, and you are here trying to do it outside the class. You shou‍ld override the toString method.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!