Module: | Classes, Objects, OOPs & Inheritance
Q38: Consider the following statements regarding String immutability and architecture:
1. The 'String' class in Java is explicitly declared with the 'final' keyword, strictly preventing any subclassing that could be used to maliciously override its immutable behaviors.
2. Immutability guarantees absolute thread safety, allowing multiple concurrent execution threads to read and share the exact same String object without requiring explicit synchronization locks.
3. Whenever a developer utilizes the addition operator (+) to concatenate two existing strings, the original underlying memory object is expanded and permanently mutated to hold the newly appended characters.
Which of the above statements is/are correct?
2. Immutability guarantees absolute thread safety, allowing multiple concurrent execution threads to read and share the exact same String object without requiring explicit synchronization locks.
3. Whenever a developer utilizes the addition operator (+) to concatenate two existing strings, the original underlying memory object is expanded and permanently mutated to hold the newly appended characters.
Which of the above statements is/are correct?
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because a String object physically cannot be mutated. Concatenation using the '+' operator creates a brand new, separate String object containing the combined text, leaving the original memory objects completely untouched.Structural Breakdown: Internally, a String holds an array of characters (in older Java, a char[