Originally posted by SomeswaraRao Vudattula: Hi Chitra,
when u r declaring the final var and using.. thete.. no probes...i meen no need the casting..
but when u r using the other class final var int,we need the casting.. because.. until runtime that dont know the type of variable.. so it need casting...
i hope now u r clear...
pls give last conclusion ..
using final int j=9; // using directly this will give error need casting using int m=0; // same above
using final static int n=8; // don't need casting casting need if final is intialized in constructor ?
can you pls give the final conclusion
when we need casting and when not..
and what if on constructor is intilizing final primitive and on does not will the complier error is not create if use that constructor which will intialize final variable and will compiler error will generate when using the construcot which does not intitilize the final variable value..
I think your :roll: is not appropriate here, Amit. You ask a lot of questions. And many times when someone takes the time to respond and compose a good reply, you reply that you didn't understand, could someone please explain more clearly. If you do understand, you usually immediately follow up with another question. As I write this, I've just read about ten posts in a row from you where you are impatient for responses in different threads. It's hard to keep up with all these questions, and personally I'm not really inclined to try. I think you might get better results here if you didn't ask so many questions at once - instead, try harder to find some of these answers yourself, and save your questions only for the things you can't find out otherwise. Remember, every time you ask a question here, you're asking for a favor from someone, for them to take their time to try to explain something for you. Now many of us are here because we enjoy doing that sort of thing - but we also like to see students putting some real effort into their studies, taking responsibility for researching things themselves rather than always asking questions of others. There are many good books out there, and writing code yourself is always the best way to learn. I hope that helps... [ June 05, 2005: Message edited by: Jim Yingst ]
Quoted from JLS2 18.104.22.168 final Fields: ------------------------------------------------- A blank final instance variable must be definitely assigned (�16.8) at the end of every constructor (�8.8) of the class in which it is declared; otherwise a compile-time error occurs. -------------------------------------------------
A final instance variable must be assigned with a value, either during the declaration or in the constructor like the following:
And once a final variable is assigned with a value, any attempt to reassign it will result in compile-time error.
[ June 06, 2005: Message edited by: Joyce Lee ]
Joined: Mar 14, 2003
its a request again to pls put light on the post and give the final confulsion... i would be really gr8full to you ppl