wanted to know a thin-line difference between STATIC and FINAL, though both are using for a CONSTANT(GLOBAL) PURPOSE (almost like C++). is that something that final adds more means to static or it's for class as well so that class can't further extend.
that would great if i have (FINAL) concept for variable, method and class.
The following is also true for methods and variables
Final
Method Method cannot be changed by subclasses
Variable When a variable is given a value that value cannot be changed.
Static Method The method belongs to the class and not to the objects which are created. This means al the objects from the class share the same method. Also you can use the methods directly without making a object
Variable The variable belongs to the class so al objects share the same variable en can access it. So if Object A of the Class changes a static variable an Object B of the same class will see the change.
We're a friendly group, but we do require members to have valid display names.
Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.
Please edit your profile and correct your display name. Thanks, and have fun!
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Something they didn't tell you is why the name static is used. The data are in a static location in memory, unlike instance variables which are dynamic. Instance variables are put into memory when they are created, and can be removed again when they are finished with. Static data on the other hand remains in memory until the JVM terminates.
As far as I know, a static member is loaded into memory once and once only when the class is loaded, which is actually before execution starts. That is why there is only one copy of each static member. So all instance of the class have access to that same member. But when the static member is loaded, the instance members are not yet in memory. So a static method cannot gain access to the instance methods or fields. Since "this" and "super" refer to the present instance of the class, or that proportion of the present instance of the class which is inherited, they are treated rather like instance members. So you can't use "this" or "super" in a static method.
People have told you about final. There are two sorts of final variables; constants (usually like this) or variables which cannot be changed after they are initialised. As far as I can remember, a final instance field must be initialised not later than the constructor call, and cannot then be reassigned. There are also final local variables and method call parameters, but I shall keep quiet about them.
[edit]Minor spelling errors and bits missed out[/edit] [ February 11, 2007: Message edited by: Campbell Ritchie ]