Given:
1. public class ItemTest {
2. private final int id;
3.
4. public ItemTest(int id) {
5. this.id = id;
6. }
7.
8. public void updateId(int newId) {
9. id = newId;
10. }
11.
12. public static void main(String[] args) {
13. ItemTest fa = new ItemTest(42);
14. fa.updateId(69);
15. System.out.println(fa.id);
16. }
17. }
What is the result?
A.
Compilation fails.
B.
An exception is thrown at runtime.
C.
The attribute id in the ItemTest object remains unchanged.
D.
The attribute id in the ItemTest object is modified to the new value.
E.
A new ItemTest object is created with the preferred value in the id attribute.
Explanation:
Main.java:9: cannot assign a value to final variable id
id = newId;
^
1 error
A