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

Why do we need autoboxing in java?

0 Answers  


What is the alternate of 'Inheritance' ?

4 Answers   CybAge, HCL,


What is a method vs function?

0 Answers  


can we have virtual functions in java?

11 Answers   Wipro,


What is sorting in java?

0 Answers  


Why synchronization is important?

0 Answers  


How will you add panel to a frame?

0 Answers  


What is bigger kb or mb?

0 Answers  


What is “try and catch” in java

2 Answers  


How many types of memory areas are allocated by jvm?

0 Answers  


worst case complexities of Quick sort and Merge sort.

0 Answers   Amazon,


Why vector is used in java?

0 Answers  


Categories