How to define a constant variable in Java?



How to define a constant variable in Java?..

Answer / vidya bhushan dwivedi

The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also.

static final int MAX_LENGTH = 50; is an example for constant.

Is This Answer Correct ?    6 Yes 0 No

Post New Answer

More Core Java Interview Questions

What does the “static” keyword mean? Can you override private or static method in java?

0 Answers  


what is the use of abstract class?

3 Answers   Amdocs, Atos Origin, Invictus,


Can a static method be final?

0 Answers  


What is the return type of the main method?

0 Answers  


Explain about OOPS concepts and fundamentals.

0 Answers   Syntel, Visa,


What does int [] mean in java?

0 Answers  


Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?

0 Answers  


What is the default value stored in Local Variables?

5 Answers  


why are there separate wait and sleep methods? : Java thread

0 Answers  


Can you add null to a list java?

0 Answers  


What is strings in java?

0 Answers  


What all methods are used to prevent thread execution ?

0 Answers  


Categories