Multiple choice technology programming languages

Which of the given options code is correct and will not waste memory.

  1. Item im = new Item(null); im = (Item ) itemList.get(0);

  2. Item im = new Item(“Done”); im = (Item ) itemList.get(0);

  3. Item im = null; im = (Item ) itemList.get(0);

  4. All of the above.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Declaring a reference variable as null and then assigning it to an existing object from a list avoids allocating unnecessary memory for a new object that would immediately be discarded and garbage collected.