Multiple choice technology programming languages

Which is simplest code snippet you will add in the main function to set the name attribute of 50th in the ItemList to “Done”?

  1. im.name = "Done";

  2. Item otherObject = new Item(“Done”); itemList.set(49, otherObject);

  3. ((Item)itemList.get(49)).name = “Done”;

  4. None of above is correct as they are not changing 50th element.

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

Option A is the simplest approach if 'im' is already a reference to the 50th element. The question asks for the simplest code snippet to add, and directly setting the name attribute with 'im.name = "Done";' is the most concise. Option C is more explicit but verbose - it retrieves the element and sets the name in one statement, which is self-contained but not the 'simplest' to add if im already exists.