Java final keyword

Introduction

A field can be declared as final.

We cannot modify final field.

We can use final to create constant values.

We must initialize a final field when it is declared.


public class Main {
  static final int FILE_NEW = 1;

  public Main() {
    // FILE_NEW = 2; error
  }//from w w w . j  av  a2 s . c o m

  public static void main(String args[]) {
    System.out.println(FILE_NEW);
    System.out.println(Main.FILE_NEW);
  }
}



PreviousNext

Related