Hi, This is from page 66 of Head First Java. Can someone explain to me how they\
ID: 3586492 • Letter: H
Question
Hi,
This is from page 66 of Head First Java. Can someone explain to me how they're coming to the solution? I'm confused despite looking at it for a long time.
puzzle: Heap o' Trouble claas HeapQuiz f int id = 0; public static void main (String A Heap o' Trouble int x 0; HeapQuizt A shert ava program is listed to the right. When'W do stufl'is reached ome objects and some refesence varl- ables will have been created. Your task h to determine which of the reference variables refer to which objects Nea al the refesence vaniables will be used, some objects might be referred to more than once. Draw ines connecting the reference variables with their matching objects whileExplanation / Answer
Heapquiz[] hq = new Heapquiz[5];
Here array of 5 objects of Heapquiz class is declared .
using while loop for x = 0,1,2 , the id of array objects is initialized as 0,1 and 2
hq[0].id = 0
hq[1].id = 1
hq[2].id = 2
hq[3] = hq[1] so hq[3].id = hq[1].id = 1
hq[4] = hq[1] so hq[4].id = 1
hq[3] = null
hq[4] = hq[0] so hq[4].id = 0
hq[0] = hq[3] so hq[0] = null
hq[3] = hq[2] so hq[3].id = 2
hq[2] = hq[0] so hq[2] = null
hq[0].id is not assigned as hq[0] = null
hq[1].id = 1
hq[2].id is not assigned as hq[2] = null
hq[3].id = 2
hq[4].id = 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.