What is difference between in the following statements
String name = "Tiger";
final String name ="Tiger";
Although the String class is final class, why do we need to create a String “CONSTANT” variable as final?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
finalin this context means that the variablenamecan only be assigned once. Assigning a differentStringobject to it again results in a compile error.I think the source of the confusion here is that the
finalkeyword can be used in several different contexts:See the Wikipedia article on final in Java for examples on each case.