String str[] = new String[3];
Can someone explain to me the memory map for the above line. How many objects and ref it will have?
That line allocates one object, which is an array of three String references. These references are initialized to null by default.
It also defines str as a local variable holding a reference to an array of Strings. It initializes the variable with a reference to that object it just created.
So you have this diagram:
str (local variable)
+--------+ array object
| -----+---------> +-------------+
+--------+ | null | (can hold a reference to a String)
+-------------+
| null | (can hold a reference to a String)
+-------------+
| null | (can hold a reference to a String)
+-------------+