Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OOP reference meaning

Status
Not open for further replies.

toyt78

Technical User
Apr 5, 2005
125
US
Code:
Box myData = new Box();

Request clarification for exactly what is going.
Here is how I how think it works:
myData is a reference (or pointer?) to an object (which is also an instance?) of type Box. So myData has a reference address sort of like this: sdsafd@34234 which is the address in the heap memory of the object or instance of type Box? This address (sdsafd@34234) basically represents the object of type Box??

If I was to print myData right now it would print out the memory address which Java uses to reference to the object in heap? But the actual value of the this object is really null at this time because I have not assigned any value to it?
 
Reference to a Box named myData, a Box-object and instance of type Box is correct.

after calling that line, the object is not null, but a new Box, as you told.

sdsafd@34234 doesn't look like an adress to me (perhaps the email-adress? is it a mailbox? :) <just kidding>

It looks a bit like the hashcode of the Box. (a Java-auto-generated code, which is used if you don't override hashCode (), and which is often used behind the scene.

myData is not a pointer, because we only have the NullPointer in Java - no other pointers.


seeking a job as java-programmer in Berlin:
 
please do not post standard Java questions in the J2EE forum.
forum269 is for J2SE / general Java questions.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top