GeekInterview.com
Answered Questions

Why is that the final variable has to be initialized as soon as it is declare?

Asked By: vishalanand_154 | Asked On: Jul 31st, 2008

Star Read Best Answer

Editorial / Best Answer

Answered by: r.praveenkumar

View all answers by r.praveenkumar

Member Since Oct-2007 | Answered On : Aug 1st, 2008

when a variable is declared as final we cant change its value again. we use final variable to declare a constant so when we declare a variable as final and if we were allowed to not to give its value at the time of declaration it would not make sense so people who designed java made mandatory to give the value when we declare a final variable. then only it will be sensible.
final PI=3.14;
then we cant change PI's value. think if the above statement do not contain a vl it would not make sense.

Answered by: Nitin Maulekhi on: Jul 18th, 2012

final keyword can be applied on:- 1.class 2.member functions(only non-static) 3.data-members(both static and non-static) 4.local variables. 1.by making a class final ,that class cannot be inherited....

Answered by: Rohit Verma on: Jul 10th, 2012

Like any variable, a final variable can also be first declared and then assigned a value. But it can be only assigned a value once and only once ( as its final variable ). for example :- final Strin...

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: