#What does this output mean ?

1 messages · Page 1 of 1 (latest)

glossy salmon
#

i have a program that gives me an address like output even tho java isn't pointer-based language, so what is this output ?

it's something like this:

classname@4429dd3e.

plucky sandBOT
#

<@&987246399047479336> please have a look, thanks.

plucky sandBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

rocky palm
glossy salmon
#

does it have an actual name ?

rocky palm
#

And it outputted that because you tried to transform the object into a string and java didn't know what to do

rocky palm
glossy salmon
#

like does it have an acronym ?

#

i know it's hard to understand me I'm kinda bad at explaining

rocky palm
#

hashcode ?

#

like I said in my first message

glossy salmon
#

so no matter what i do, the output will be a hashcode ?

rocky palm
#

no

#

you could try to directly print the name for example

#

instead of trying to print the whole object

#

or you could override toString

glossy salmon
#

yeah that's whay i thought using setters and getters

#

but I'm asking because it was a question on my quiz and i was so frustrated by it

#

thx btw you're a life saver

rocky palm
#

what was the question ?

glossy salmon
#

what is the output of the following program.

rocky palm
#

ah yes, it's ClassName@hashCode

#

A complete answer would be : "This problem would print out the default implementation of Student class, which would return ClassName@hashCode ie Student@4429dd3e"

glossy salmon
#

thank you so much

cobalt moat
#

@glossy salmon Technically it is called the "identity hash code"

#

hash code can be overridden

#

while java isn't a pointer based language, most classes have a defined "identity" associated with them

#

and that identity stays constant for the object's entire lifetime

#

you can squint and say "oh its the memory address!" but that isn't true since the jvm will shuffle things around and actual pointers change

#

right now the only kinds of objects are those with identity that are behind a reference

#

and primitive objects that do not have an identity and are not behind a reference (like int, double, etc)

#

in the future that will change, but its a far-ish future

#

where there will still be identity classes behind references

#

but also value classes, which are behind references but do not have an identity

#

and primitive classes, which work exactly like an int