Hello All, I am wondering when it is appropriate to use Static and/or Final and what the difference is. TIA.
Joined: Oct 13, 2005
That is a bit like asking whether you should eat ice cream or drink coffee. The two are as different as chalk and cheese.
If you can manage it, use final a lot on variables. It means a variable can be set up once and once only. After that it cannot be reassigned. It makes it easier to watch the values of variables. The final keyword can be applied both to fields and to local variables. It can also be applied to classes and methods, but that is something different.
The static keyword means the field (or method, or nested class) "belongs" to the class, not to an individual instance, and this is totally different. A static field is one you want to share between all instances of the class (or public static final = use as a constant). A static method is one which takes no information from a particular instance of the class and applies no information fro any particular instances.
I am sure other people will have their own opinions