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

1 answer 164 views
1 answer 178 views
4 answers 437 views
437 views asked May 23, 2018 by avibootz
1 answer 177 views
2 answers 200 views
200 views asked Oct 13, 2016 by avibootz
4 answers 256 views
4 answers 349 views
349 views asked Nov 2, 2015 by avibootz
...