Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
The final keyword is the means to enforce this in Java, whether it's used on methods or on classes. The keyword final itself means something is final and is not supposed to be modified in any way. If a class if marked final then it can not be extended or sub-classed. 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.) If Java is object oriented, and you declare a class final, doesn't it stop the idea of class having the characteristics of objects? In some sense yes. 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.) related article: https://programming.guide/java/when-to-create-a-final-class.html https://stackoverflow.com/questions/5181578/what-is-the-point-of-final-class-in-java
9th Oct 2018, 10:15 AM
Willem Roos