View RSS Feed

Core Java

Final Fields and Methods

Rate this Entry
by , 03-02-2012 at 05:20 PM (1374 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];

Submit "Final Fields and Methods" to Facebook Submit "Final Fields and Methods" to Digg Submit "Final Fields and Methods" to Submit "Final Fields and Methods" to StumbleUpon Submit "Final Fields and Methods" to Google

Tags: final fields Add / Edit Tags