+ 9

References and Objects

How many references and objects in this code : Circle[] circle = new Circle[10];

23rd Apr 2019, 5:59 PM
Mays Qunaibi
Mays Qunaibi - avatar
17 Respostas
+ 8
Well since we have an array of size 10, so we have 10 references and each reference is pointing to one object so we have 10 objects.
24th Apr 2019, 10:04 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
Mays Qunaibi In Java you donot need to initialize the array. Their default value will be zero/null depending on the data type.
23rd Apr 2019, 7:17 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
Mays Qunaibi There was a little confusion Circle[] circle = new Circle[10]; Above line creates an array of 10 references of type circle which have null value (or you can say they are pointing to null) To initialize them you can use for loop for (int i = 0; i < 10; i++) circle[i] = new Circle(); Now each reference in the array will be pointing to object.
24th Apr 2019, 7:22 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 5
I think 1 reference: circle is the reference to the array. 10 objects: The array have 10 objects of type Circle stored/ initialized.
23rd Apr 2019, 6:49 PM
Anya
Anya - avatar
+ 4
I want to know this also !!!
23rd Apr 2019, 6:02 PM
Jannat Natsheh
Jannat Natsheh - avatar
+ 3
Anybody can help us ??
23rd Apr 2019, 6:02 PM
Jannat Natsheh
Jannat Natsheh - avatar
+ 3
but the objects in the array not initialized yet they just have referencesđŸ§đŸ€”đŸ€”
23rd Apr 2019, 6:59 PM
Mays Qunaibi
Mays Qunaibi - avatar
+ 3
nAutAxH AhmAd i mean arrays which stord objects....stord the references of thier objects ....here we creat an array but didn’t creat any objects...just didn’t assign itđŸ€”đŸ€”
23rd Apr 2019, 7:30 PM
Mays Qunaibi
Mays Qunaibi - avatar
+ 3
Yes in this case that we are just create an array without assign any value ..can we say it has 10 objects or it has 10 references ?
23rd Apr 2019, 7:34 PM
Jannat Natsheh
Jannat Natsheh - avatar
+ 3
zemiak so do u think there’s 10 null object’s are already created...??đŸ€”
23rd Apr 2019, 8:01 PM
Mays Qunaibi
Mays Qunaibi - avatar
+ 3
zemiak mmmm...maybe ..but you still didn’t spicified ...if “it’s described as reference to nothing”.. so will count it with reference or objects ??that’s what i confused with when i’m trying to answer this today🙃🙃thanks for discuss🌾
23rd Apr 2019, 10:05 PM
Mays Qunaibi
Mays Qunaibi - avatar
+ 3
nAutAxH AhmAd so what is the final answer ?what is the count of objects and how much references we have ?
24th Apr 2019, 8:59 AM
Jannat Natsheh
Jannat Natsheh - avatar
+ 3
nAutAxH AhmAd cool... so do u think the reference of the array count with this 10 referencses ??
24th Apr 2019, 9:03 AM
Mays Qunaibi
Mays Qunaibi - avatar
+ 1
null is not object, it has not class, rather it is value or type,it is described as "reference" to nothing, but actually there is no address referenced to place in memory.
23rd Apr 2019, 9:23 PM
zemiak
0
there is 1 reference to object in circle variable, 10x null in array are not references class Circle {} Circle[] circle = new Circle[10]; int i=0; System.out.println(circle); for(var c : circle){ System.out.println("["+i++ +"] "+c); } //output [LProgram$1Circle;@77468bd9 [0] null [1] null [2] null ... [8] null [9] null
23rd Apr 2019, 7:54 PM
zemiak
0
Salut
25th Apr 2019, 8:38 AM
L'incomparable MoMo
L'incomparable MoMo - avatar
3rd Jul 2019, 1:39 PM
Maximiliano Antichi
Maximiliano Antichi - avatar