How to Declare Constant in Java


In this example we will show the method to declare a constant in Java.

Source Code

package com.beginner.examples;

public class ConstantExample {

    public static void main(String[] args){
    	final double PI = 3.14;
    	
    	//PI = 3.1415926;//The final local variable PI cannot be assigned.
		System.out.println("PI is : "+PI);
    }
}

Output:

PI is : 3.14
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments