final private vs private final

Solutions on MaxInterview for final private vs private final by the best coders in the world

showing results for - "final private vs private final"
Luis
19 Jan 2019
1There is no difference between private final and final private.
2
3public class TestClass {
4
5    private final String i1;
6    final private String i2;
7    private final String i3 = "test"; // ok
8    private final String i4; // not ok, never initialized
9
10    TestClass() {
11        i1 = "test1"; // ok
12        i2 = "test2"; // ok
13        i3 = "test3"; // not ok, overrides already set value
14    }
15
16    void mod() {
17        i1 = "test0"; // not ok, can't edit final i1
18    }
19}
20