Final class in Java here we have best answer for this question.
A final
class is simply a class that can’t be extended.
(This does not mean that all references to objects of the class would act as if they were declared as final
.)
By marking a class as final you disable a powerful and flexible feature of the language for that part of the code. Some classes however, should not (and in certain cases can not) be designed to take subclassing into account in a good way. In these cases it makes sense to mark the class as final, even though it limits OOP. (Remember however that a final class can still extend another non-final class.)
In Java, items with the final
modifier cannot be changed!
This includes final classes, final variables, and final methods:
- A final class cannot be extended by any other class
- A final variable cannot be reassigned to another value
- A final method cannot be overridden