References and Objects | Sololearn: Learn to code for FREE!

+9

References and Objects

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

4/23/2019 5:59:21 PM

Mays Qunaibi

17 Answers

New Answer

+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.

+7

Mays Qunaibi In Java you donot need to initialize the array. Their default value will be zero/null depending on the data type.

+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.

+5

I think 1 reference: circle is the reference to the array. 10 objects: The array have 10 objects of type Circle stored/ initialized.

+4

I want to know this also !!!

+3

Anybody can help us ??

+3

but the objects in the array not initialized yet they just have references🧐🤔🤔

+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🤔🤔

+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 ?

+3

zemiak so do u think there’s 10 null object’s are already created...??🤔

+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🌸

+3

nAutAxH AhmAd so what is the final answer ?what is the count of objects and how much references we have ?

+3

nAutAxH AhmAd cool... so do u think the reference of the array count with this 10 referencses ??

+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.

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

0

0

https://code.sololearn.com/W3DwP01zcgMq/?ref=app