Long description

Back

The block of code consists of six lines of code. Line 1: var a b c equals 27 semicolon Line 2: var d e f equals open double quotes hello close double quotes semicolon. Note: Line 1 and Line 2 is marked variables with primitive types. Line 3: var f o o equals open square bracket 45 comma 35 comma 25 close square bracket semicolon. Note: Line 3 is marked variable with reference type (i. e., array object). Line 4: var x y z equals def semicolon. Line 5: var bar equals f o o semicolon. Note: Line 4 and Line 5 is marked these new variables differ in important ways (see below). Line 6: bar open square bracket 0 close square bracket equals 200 semicolon. Note: Line 6 is marked changes value of the first element of array.

Memory representation of values are as follows:

There are five memory blocks labeled a b c, d e f, x y z, f o o, and bar and are placed one below the other. The block corresponding to a b c has the value 27. The block corresponding to d e f has the value open double quotes hello close double quotes. The block corresponding to x y z has the value open double quotes hello close double quotes. Note: a b c, d e f, and x y z memory blocks is marked Each primitive variable contains the value directly within the memory for that variable. The blocks corresponding to f o o and bar consists of a pointer, which points to a sequence of memory for f o o object instance. The sequence of memory consists of a list of three values. First: 45. Second: 35. Third: 25. Note: First: 45 is marked This element will get changed to the value of 200. Thus, both f o o open square bracket 0 close square bracket and bar open square bracket 0 close square bracket will have the same value open parenthesis 200 close parenthesis.

The memory block labeled bar is marked Each reference variable contains a reference (or pointer) to the memory that contains the contents of that object.

Back