Originally posted by Sagar:
Why does one need to declare a variable as both static final? for eg interface variables are implicitly final..
Anyone with an example...this isn't striking me .
okay. Here is the deal,
1. static is used to declare 'class' level variable. Now, it could be the case that we want to allow changing the value for this variable.
2. final is used to say 'none can change the variable's value after it gets initialized once'
I did googling on this and I would consider
this link for our reference in the explanation.
If we apply the above two point of knowledge then we could see-
1. some variable may just have to be static only. e.g. the variable shapesCount is just static variable in ShapesCounter class. Why? Because we wanted that variable to get updated by each of the Shapes when they get created, right?
2. some variable may need to be final "in addition to being static". e.g. maxShapeCount variable in ShapesCounter is "final". Why? Because we want to restrict maximum number of Shapes objects in our application to 100.
Does this make sense?
What is the purpose of assigning a constructor as a static ..can it be assigned at all.
Constrcutor can't be static. May be somebody can provide you a link of JLS (
Java Language Specification)'s particular section about this....
Regards
Maulin