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

How are this() and super() used with constructors?

9 Answers  


Explain about field hiding in java?

0 Answers  


Is java free for commercial?

0 Answers  


What does the @override annotation do?

0 Answers  


what are upcasting and downcasting?

5 Answers  






Is java a pure object oriented language?

0 Answers  


What does you mean in math?

0 Answers  


Tell me the programme for this @ 1 2 @ @ @ 1 2 3 4

5 Answers   Accenture, iGate, IntoNET, Value Labs,


How do you compare objects in java?

0 Answers  


Is it possible to do method overloading and overriding at a time

3 Answers   L&T,


Why java is considered dynamic?

0 Answers  


Suppose there is an Online shopping cart application having different objects like Cart, SelectionItem, Billing, COnfiguration, Authentication, Authorization, PersonalDetails etc. Out of this which one can be made a singleton pattern and why?

2 Answers   RBS,


Categories