+ 11
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
7 ответов
+ 11
@mehdi but what is the purpose of doing this when my [0] is already an object?
+ 11
@Ettienne thanks alot. that makes it crystal clear
+ 10
still not sure if i get the point but its okay
+ 2
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).
+ 1
its because where my[0] should store
object can store in object array
+ 1
just do it. 😇
0
your books array should be extends object and its will work successfully