Originally posted by iti garg:
first of all please tell me what does this line mean---
Hq[x].id = x;
I dont understand meaning of this line.[/QB]
Howdy iti
This code ostensibly (I'll get back to why I say ostensible in a bit) makes an array of 5 objects of type
HeapQuiz. Each of these objects has its own copy of the instance variable
id. To access the variable
id of a particular object we identify the object
Hq[x] followed by a "dot" followed by the name of the variable. Thus we are saying: "In the array
Hq assign the value of the local variable
x to the value of the instance variable
id belonging to the object of type
HeapQuiz stored at the location
[x] in the array." So if
x equaled 0 we would
ostensibly be saying "Assign 0 to the
id of the
HeapQuiz object stored at
Hq[0] (the first position in the
HQ array)."
Now if I were trying to figure out "which of the reference variables refer to which objects" I would type the code into a text editor, at the end of the code add a bunch of clunky statements to show me the values of each of the elements of the array, something like:
system.out.println("Variable id of hq element 0 = " + hq[0].id);
etc. and then compile & run the code.
The programmers I respect the most & who seem to know the most are like the hero of those "Bourne" movies. They trust no one. Not their teachers, not the book, not other programmers. They check the answer for themselves by running code. Also, ditto what Campbell said. He is one of the programmers I am talking about. Did I just say he was like Matt Damon?!
If you do that in this case, you will find out what I mean by "ostensible". I'll give you a hint: Java is case sensitive. I'll give you another hint too: There are at least two other compile-time errors in the code as you posted it, also due to "case insensitivity." How do I know? I typed the code in & tried to run it.
[ October 29, 2008: Message edited by: Ken Kisser ]