Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

3. Primitives and References: Know Your ... > An object reference is just another ...

An object reference is just another variable value

Something that goes in a cup. Only this time, the value is a remote control.

Primitive Variable

byte x = 7;

The bits representing 7 go into the variable. (00000111).

image with no caption

Reference Variable

Dog myDog = new Dog();

The bits representing a way to get to the Dog object go into the variable.

The Dog object itself does not go into the variable!

image with no caption

Note

With primitive variables, the value of the variable is... the value (5, -26.7, ‘a’).

With reference variables, the value of the variable is... bits representing a way to get to a specific object.

You don’t know (or care) how any particular JVM implements object references. Sure, they might be a pointer to a pointer to... but even if you know, you still can’t use the bits for anything other than accessing an object.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial