What is considered an object in this matter? The array has 7 doubles plus the array itself.
How many objects will be present after the next code fragment is executed?
double[] ann = new double[ 7 ]; double[] bob; bob = ann;
2 7 14 1
only one object new double[ 7 ];
new double[ 7 ];
double [] bob; also refers to the same object created in the previous step.
There will be only one object. The one you create with new double[7]. boband ann- these are just references to this object, and 7 doubles are primitives.
new double[7]
bob
ann
: double[7], 2 (ann bob). , Object,
double[7]
Object
double[] ann = new double[ 7 ];
Array Object, Reference ann.
Array Object
double[] bob; bob = ann;
In the line above, you create a reference variable for the array object bob. And assigning a link to Array Objectthat is also mentionedann
Thank. I tested it with some code.
public class TestCode { /** * @param args */ public static void main(String[] args) { double[] ann = new double[ 7 ]; double[] bob; bob = ann; System.out.println(bob.getClass().getSimpleName()); System.out.println(bob[6]); //there are 7 double references initialized to 0.0 //array refs point to same object //1 object of type double[] } }