This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
If you don't want a member variable of a class to be changed in any way then what would you do? 1) Make it private 2) Make it public 3) Make it final 4) Make it private and provide an accessor method that returns its value. I think the answer could not be final because Even you have declared member variable as final and you haven't intialized it you can intianlize it in constructor. So, then answer cannot be final? Can anybody else think what could be the posiible answer ?
So you want to have an unitialized value to be final and you cannot set to anything in the constructor? What would be the use of that? I think "final" is the right answer. At the very least, this is its purpose.
The answer is final, because final variables must be initialized once and only once. A final variable is a constant. This means that it only has one value in its entire lifetime. Before initialization, it is not considered to have a value.