Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardJavafinal-field publicationSingle-choice MCQ

A class has a final field initialized in the constructor to a freshly allocated int[]. After the object is safely published, another thread reads the array and then mutates arr[0] from a separate thread without synchronization. Which statement about the final-field guarantee is correct?

class Holder { final int[] arr; Holder() { arr = new int[]{1}; } } // thread X: Holder h = new Holder(); (published safely) // thread Y: h.arr[0] = 2; (no sync)