Object array | SoloLearn: Learn to code for FREE!


Object array

e.g if we have one class books and we declare array books[] my = new books [5]; my [0] = new book (); what will this do??? can anyone explain

2/23/2017 8:32:42 AM

adeel salim

7 Answers

New Answer


@mehdi but what is the purpose of doing this when my [0] is already an object?


@Ettienne thanks alot. that makes it crystal clear


still not sure if i get the point but its okay


You are reassigning the my[0] reference in the array to point to a new book. The previous reference is overwritten, meaning the previous book does not now have any references pointing to it - it is now basically 'garbage' and the GC will collect it on its next GC cycle (i.e. run its finalizer and then delete it).


its because where my[0] should store object can store in object array


just do it. 😇


your books array should be extends object and its will work successfully