10. Abstract Classes and Interfaces

 
[Page 321 ( continued )]

9.12. The final Classes, Methods , and Variables

You have already seen the final modifier used in declaring constants. You may occasionally want to prevent classes from being extended. In such cases, use the final modifier to indicate that a class is final and cannot be a parent class. The Math class, introduced in Chapter 5, "Methods," is a final class. The String and StringBuffer classes, introduced in Chapter 8, "Strings," are also final classes.


[Page 322]

You also can define a method to be final; a final method cannot be overridden by its subclasses.

Note

The modifiers are used on classes and class members (data and methods), except that the final modifier can also be used on local variables in a method. A final local variable is a constant inside a method.


 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net