Why must a final variable be initialized before constructor completes?
public class Ex
{
final int q;
}
When I compile this code I get er
The final
keyword applied to a field has one of two effects:
final HashMap a
, you will only be able to set it once, and you won't be able to do this.a=new HashMap();
again, but nothing keeps you from doing this.a.put("a","b")
,s since that doesn't modify the reference, only the content of the object.