How to define and use constant type in Java

2 Answers

0 votes
public class MyClass {
    public static final int LEN = 100;

    public static void main(String args[]) {
        System.out.println(LEN);
        //LEN = 99; // error: cannot assign a value to final variable LEN
    }
}



/*
run:

100

*/

 



answered Jul 20, 2020 by avibootz
0 votes
public class MyClass {
    public static final int BLUE = 0x333cff;
    public static void main(String args[]) {
        System.out.println(BLUE);
        //BLUE = 0x333aaa; // error: cannot assign a value to final variable LEN
    }
}



/*
run:

3357951

*/

 



answered Jul 20, 2020 by avibootz

Related questions

...