When we have a final instance variable of a class, is it instantiated for each object created of the class or just created once and referred?
And what is the case if the final variable is a local class variable??
When we have a final instance variable of a class, is it instantiated for
Share
Final variables is instantiated for each instance of the class. The values once assigned to them may not be changed. These variables may be initialized once, either via an initializer or an assignment statement.
What you are referring to are the static variables. These variable is not attached to a particular object, but rather to the class as a whole. They are allocated when the class is loaded.
Taking these two together, you can have a static final variable for the class. This basically means that the value assigned to the variable once assigned is constant and that it would be attached to a class rather than an instance of the class.