Answers for "final private vs private final"

0

final private vs private final

There is no difference between private final and final private.

public class TestClass {

    private final String i1;
    final private String i2;
    private final String i3 = "test"; // ok
    private final String i4; // not ok, never initialized

    TestClass() {
        i1 = "test1"; // ok
        i2 = "test2"; // ok
        i3 = "test3"; // not ok, overrides already set value
    }

    void mod() {
        i1 = "test0"; // not ok, can't edit final i1
    }
}
Posted by: Guest on August-25-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language