What I think is final instance variable get their default values if not initialized
class Finale
{ final int x;
final
String s;
public static void main(String args[])
{
System.out.println(new Finale().x);
System.out.println(new Finale().s);
}
}
compiler says x might not have been initialized
So does that mean final instance variable don`t get their default values.
and the other one is
class Cant_Initialize
{
final int x;
public static void main(String args[])
{
Cant_Initialize c=new Cant_Initialize();
c.x=10;
}
}
Now compiler says can`t assign value to a final variable
so does it means that final instance variable have to be initialized when they are declared
class Constant
{
final int x=10;
}
Last one , final without static .So does it mean that every instance of class Constant will have its own final int x variable.
And since it makes no sense that each instance to have a final variable so we make it static