Multiple choice technology platforms and products

Which code will not compile?

  1. final String abc = "Neeraj"; abc = "Rathi";

  2. final String abc;abc = "Rathi";

  3. final ArrayList al = new ArrayList();al.add("Neeraj");al.add("Rathi");

  4. final int i; i = 0;

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

A final variable can only be assigned once. In option A, abc is declared final and initialized with 'Neeraj', then reassigned to 'Rathi' - this is illegal. Options B and D are legal blank finals (declared final, assigned once later). Option C works because the reference is final, not the contents - you can modify the list but not reassign al.