0

I created a class named create and its objects ob and ob1. Then I used ob.toString() and ob1.toString() and printed them using System.out.println().

I got some strange outputs.

create@a267b0,create@9de93c and as on.

Where does that output come from and what does it mean?

khelwood
  • 55,782
  • 14
  • 81
  • 108

3 Answers3

0

This is the default behavior of toString method defined in Object class. It simply return the class name + a unique identifier (which is basically the hashCode's hexadecimal notation ).

If you want to provide more specific strings for toString method, override the toString method in your custom class and return more realistic text that describe the object)

ABHIJITH GM
  • 134
  • 4
0

This is the hexadecimal representation of your two instances of your class create.

Chris311
  • 3,794
  • 9
  • 46
  • 80
0

This is class name + @ + hashCode() which is default behavior of toString() method inherited from Object. You have to override this method to get desired string representation:

@Override
public String toString() {
   return ... // put here what you need to return
}
Yevhen Danchenko
  • 1,039
  • 2
  • 9
  • 17