2.16 Final Methods and Classes2.15 Shadowing Variables2 Java with Caffeine2.17 Abstract Classes

2.16 Final Methods and Classes

If a method is declared as final, it cannot be overridden by a method in a subclass:

   final type method(...) { ... }

If a class is declared as final, no other class may inherit from this class.

   final class Class 
   { ... }

The keyword final thus prevents unwanted extensions; furthermore it allows the compiler to generate more efficient code for method calls.


© Wolfgang Schreiner; February 3, 2005

2.16 Final Methods and Classes2.15 Shadowing Variables2 Java with Caffeine2.17 Abstract Classes