Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:37:12+00:00 2026-06-15T16:37:12+00:00

I am confused about how object references work and was wondering if someone could

  • 0

I am confused about how object references work and was wondering if someone could help. Below is some example code which is supposed to deQueue a Queue based on a linked list for the general case:

Object head = listHead.datum;
listHead = listHead.next;
return head;

My understanding is that when you have a primitive variable the actual value is stored is assigned to it, but if the variable is an object then a reference to an object is stored in there. So in the above code a reference to listHead.datum is stored in head, but then the reference stored in listHead is changed to be listHead.next. When it comes time to return the Object called head I would have thought that it would follow it’s assigned reference i.e. go to listHead (which now refers to a different place) and then to datum.

The above code should return the head of the Queue but following my logic it will return the second in the queue. Where am I going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:37:13+00:00Added an answer on June 15, 2026 at 4:37 pm

    We have:

    Object head = listHead.datum;
    listHead = listHead.next;
    return head;
    

    There are a number of references at play here:

    • listHead is a reference
    • head is a reference
    • listHead.datum is a reference
    • listHead.next is a reference

    There are two actual object instances being referenced:

    • whatever datum references (let’s call that instance D)
    • whatever next references (let’s call that instance N)

    Here’s how things go down.

    • listHead.datum has a reference to D
    • listHead.next has a reference to N
    • head is given a reference to D
    • listHead is given a reference to N (note that head is not changed)
    • you return head which still references D
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused about the object references. Please check the examples below: class
I am really confused about object relationships! I have two classes Person and Address.
I am a little confused about object assignment and pointers in Ruby, and coded
I am a little confused about Accept-Encoding . I have Web Service which would
I've always been confused/unsure about how .Net copies references. Let's say I have a
OK, I always get confused about this. Let's say I have this code. Public
I'm a bit confused about the right way to write a code. I read
I am very confused about spring controllers, pls help me. i want to know
I'm confused about the notion of prototype in javascript. When I'm defining an object
I am doing some Research work on .Net libraries and conufsed about the behavior

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.