9.5. final

Inheritance and method overriding are very powerful, as we have seen. However, there are many occasions during which you do not want to allow classes to be extended and methods to be overridden. You disallow such things with the final keyword.

There could be a number of reasons for wanting to disallow class extension or method overriding.

9.5.1. final Disallows Inheritance

In order to prevent a class from being inherited, use the final keyword in its definition:

public final class Class 

When you declare a class as final, all of its methods become implicitly final as well.

Note

As you may infer, you cannot declare a class both abstract and final. These concepts are at opposite ends of the spectrum: abstract says, “I have no implementation ...

Get Java™ for ColdFusion® Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.