Final Fields and Methods
by, 03-02-2012 at 04:20 PM (1245 Views)
Fields and methods might be declared final. For final method possibilities are not there to be overridden, in subclasses. Final field is considered to be constant: Possibility of assigning once again is not present when a value is been provided already. For example, Constructor function of the List class does the item field initialization to size ten array. For array’s initial size, usage of constant is recommendable. For whole class only 1 constant copy is needed. Hence field static as well as final shall be created.
private static final int INITIAL_SIZE = 10;
Assignment statement gets changed, in constructor function:
items = new Object[INITIAL_SIZE];