aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in final variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in final variable" Watch "doubt in final variable" New topic
Author

doubt in final variable

Vaibhav Chauhan
Ranch Hand

Joined: Aug 16, 2006
Posts: 115


why there is error at line 1. why compiler doesn't treat a as compile time constant.??
Mani Venkata Kanth
Ranch Hand

Joined: Aug 21, 2006
Posts: 39
hi...

identifier expected at declaration....
if the final variable is of int type thn thr is error...

post exact error to find the reason...
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
Hi,

What does this mean

final a;

There is no primitive type as final.

try,

final byte a;

instead.

Regards,
Praveen
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643



In java compile time constant is declared and initilized at a single line.
Variable a in your code is not compile time constant because you are declaring Variable a at one line and then initilization it at next line hence it is not compile time constant.
Check the above for compile time constant.
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
Hi,

See the below URL,

Final Variables - Definite Assignment

It says a final varaible cannot be on the left side of an assignment.

Regards,
Praveen
[ September 04, 2006: Message edited by: Praveen Babu ]
Vaibhav Chauhan
Ranch Hand

Joined: Aug 16, 2006
Posts: 115
thanks for all of you....
i am sorry that i missed identifier type ...it is

final int a;

thanks again
 
wood burning stoves
 
subject: doubt in final variable