How to declare a constant in Java/**
* @author lautturi.com
* Java example: using final keyword to declare a constant in Java
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
final double PI = 3.14159;
System.out.println(PI);
PI = 3.14; // we could not modify the value of a final variable
// Exception in thread "main" java.lang.Error: Unresolved compilation problem:
//The final local variable PI cannot be assigned. It must be blank and not using a compound assignment
}
}
S:ecruowww.lautturi.com