How to define a constant variable in Java?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain about field hiding in java?

527


What is return in java?

560


What is r in java?

595


How do you convert boolean to boolean?

525


Can we have try without catch block?

645






EDS (Electronic Data Systems India Pvt Ltd) at Chennai on 16-12-2006.

8623


Explain the meaning of java applet.

606


How to make object serializable in java?

553


Can we overload final method in java?

552


What will be the default values of all the elements of an array defined as an instance variable?

558


How many functional interfaces does java 8 have?

606


What is bom encoding?

556


How does compareto method work?

524


How do I type unicode?

540


Define the term string pool?

590