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

Explain wait() method of object class ?

0 Answers  


Is java a prime method?

0 Answers  


Why is prepared Statement, Callable Statement used for? What is the need of Batch updates?

1 Answers   Logica CMG,


What are the differences between getting and load method?

0 Answers  


What are passing parameters?

0 Answers  






State the difference between strings and arrays.

0 Answers   Syntel, Visa,


what is Vector class?

2 Answers  


Why is the main method declared static?

0 Answers  


What do you mean by platform independence of Java?

0 Answers  


How can an exception be thrown manually by a programmer?

0 Answers  


what is the meaning of java.lang and java.util

6 Answers  


Difference between array and arraylist.

23 Answers   Arise Solution, Banca Sella, iFocus, NIC, Sai Softech, Solartis, TCS, Verizon,


Categories