Java - final Class Variables

Introduction

You can declare a static variable final and blank final.

You must initialize a blank final class variable in one of the static initializers.

You can only initialize all the blank final class variables once in one of the static initializers.

Example

The following code shows how to deal with a final class variable.

class Test {
  public static final int YES = 1;
  public static final int NO = 2;
  public static final String MSG;

  static {
    MSG = "from  book2s.com";
  }
}

Related Topic