You are here: Home / Topics / Constants in Java

Constants in Java

Filed under: Java on 2023-08-11 19:12:08

// Constant example

class Constant1
{
static final int NUMBER_OF_MONTHS = 12;
static final double PI = (double) 22 / 7;

public static void main( String args[] )
{
 System.out.println("NUMBER_OF_MONTHS : " + NUMBER_OF_MONTHS );
 System.out.println("PI : " + PI );
}
}


Output:

NUMBER_OF_MONTHS : 12
PI : 3.142857142857143

About Author:
V
Vinay Kumar     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.