I have 3 objects root1,root2,root3 where they are present in root[] (Array Object) which is a collection of objects.
I have initialized the
I have 3 objects root1,root2,root3
No you don't. You have three variables, and they are all null.
where they are present in
root[]
Nothing is present in root[] except three nulls when you initialize it.
I have initialized the
Nodeclass usingroot[0]
You have instantiated the Node class, and stored the reference into root[0].
// It is printing null value.
With this code it should be throwing NullPointerException.
root[0]=root1
No it doesn't. You overwrote it in your loop, and in any case when you did the (pointless) array initialization, root1 was null, as you didn't initialize it.