If they do, when do they use it so I can understand it better and know when to use it.

A final class is simply a class that can't be extended.

(It does not mean that all references to objects of the class would act as if they were declared as final.)

When it's useful to declare a class as final is covered in the answers of this question:

  • Good reasons to prohibit inheritance in Java?

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.)

Answer from aioobe on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › final-keyword-in-java
final Keyword in Java - GeeksforGeeks
The final keyword is a non-access modifier used to restrict modification. It applies to variables (value cannot change) methods (cannot be overridden) and classes (cannot be extended).
Published   5 days ago
Discussions

Why would anyone declare a class 'final'?
I could think of a couple reasons to declare a class final: 1) it's supposed to be immutable or 2) if you have other code that depends on this class working exactly the way you've implemented it. In the case of immutability, you want to make sure that instances of the final class don't change in value once they've been created. This is important for objects that will be used as hash keys, for example. If your supposedly immutable class weren't final, someone could come along, subclass it, give your code something you expect to be immutable, then change it under your nose. The second reason is sort of a superset of the first problem. You can (hopefully) trust the code you write. If your final class implements something really important, you might not want to allow anyone to subclass it and (perhaps maliciously) override the behavior you depend on. Of course, you sacrifice flexibility for safety here. More on reddit.com
🌐 r/java
56
19
March 10, 2010
Why are final variables used in java?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
26
15
January 7, 2022
Classes final by default - Language Design - Kotlin Discussions
I understand the reasoning provided here: "By default, all classes in Kotlin are final, which corresponds to http://www.oracle.com/technetwork/java/effectivejava-136174.html">Effective Java, Item 17: Design and document for inheritance or else prohibit it." In practice, I find that this introduces ... More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
7
June 28, 2015
[Java] I keep getting "error: local variables referenced from an inner class must be final or effectively final" and have no idea how to fix it.
It's because you're accessing the result variable from inside the EventHandler. To fix it you could: Make result a member variable of the class, which you are allowed to modify Make result a final AtomicReference to a string, whose contents you are allowed to modify More on reddit.com
🌐 r/learnprogramming
5
2
August 14, 2014
People also ask

Can a final class in Java have final methods?
Yes, a final class in Java can contain both final and non-final methods. However, since the class itself can’t be extended, marking its methods as final has limited impact beyond internal clarity or intent. Yes, a final class in Java can contain both final and non-final methods. However, since the class itself can’t be extended, marking its methods as final has limited impact beyond internal clarity or intent.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › final class in java
Final Class in Java | Meaning, Method & Example Explained
Can you create a final variable in a final class in Java?
Yes, you can declare final variables inside a final class. Final variables are constants, and their values cannot be changed once assigned. They’re commonly used for defining fixed configurations or constants in Java. Yes, you can declare final variables inside a final class . Final variables are constants, and their values cannot be changed once assigned. They’re commonly used for defining fixed configurations or constants in Java.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › final class in java
Final Class in Java | Meaning, Method & Example Explained
What is the difference between final class and final method in Java?
A final class can’t be extended, while a final method can’t be overridden. Both enforce restrictions on inheritance but at different levels—class-level restriction versus method-level customization control within subclassing. A final class can’t be extended, while a final method can’t be overridden. Both enforce restrictions on inheritance but at different levels—class-level restriction versus method-level customization control within subclassing.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › final class in java
Final Class in Java | Meaning, Method & Example Explained
🌐
Scaler
scaler.com › topics › final-class-in-java
Final Class in Java | Scaler Topics
May 28, 2024 - As the name suggests, the Final Class in Java uses the final keyword for its declaration. The final keyword in Java restricts the user; similarly, the final class means that the class cannot be extended. We can only create a final class if it is complete, which means it cannot be an abstract class.
🌐
Reddit
reddit.com › r/java › why would anyone declare a class 'final'?
r/java on Reddit: Why would anyone declare a class 'final'?
March 10, 2010 -

Okay so I'm fairly new to Java programming but I've been a programmer for a long time (> 10 years). I'm currently writing an application which involves building some strings. I find myself doing this a lot:

String lineTerminator = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();
...
sb.append("blah blah blah").append(lineTerminator);

So I thought I'll just extend the Stringbuilder class and add a method:

public void appendLine(String s);

with the obvious semantics. But I find I can't do that because the StringBuilder class is declared as 'final' why?

I've vaguely googled a bit for this but the answer generally seems to be: "You would make a class Final in Java if you do not want anybody to inherit the features of your class. " and "You don't want anybody to inherit from your class because that code would not work" but I can't seem to get a reasonable explanation for why it might not work. I understand why one might declare a method as 'final' but not a class.

🌐
Baeldung
baeldung.com › home › java › core java › the “final” keyword in java
The "final" Keyword in Java | Baeldung
June 14, 2025 - Consider the situation if we can extend the String class, override any of its methods, and substitute all the String instances with the instances of our specific String subclass. The result of the operations over String objects will then become unpredictable. And given that the String class is used everywhere, it’s unacceptable. That’s why the String class is marked as final.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › IandI › final.html
Writing Final Classes and Methods (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
You use the final keyword in a method declaration to indicate that the method cannot be overridden by subclasses. The Object class does this—a number of its methods are final.
Find elsewhere
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › final class in java
Final Class in Java | Meaning, Method & Example Explained
June 24, 2025 - Final Class in Java: A tutorial on creating classes that cannot be extended or overridden, enhancing code security and design integrity.
🌐
Wikipedia
en.wikipedia.org › wiki › Final_(Java)
final (Java) - Wikipedia
October 29, 2025 - When an anonymous inner class is defined within the body of a method, all variables declared final in the scope of that method are accessible from within the inner class. For scalar values, once it has been assigned, the value of the final variable cannot change. For object values, the reference cannot change. This allows the Java compiler to "capture" the value of the variable at run-time and store a copy as a field in the inner class.
🌐
Whitman College
whitman.edu › mathematics › java_tutorial › java › javaOO › final.html
Writing Final Classes and Methods
You can declare that your class is final; that is, that your class cannot be subclassed. There are (at least) two reasons why you might want to do this: security reasons and design reasons. Security: One mechanism that hackers use to subvert systems is to create subclasses of a class and then ...
🌐
DataCamp
datacamp.com › doc › java › final
final Keyword in Java: Usage & Examples
The final keyword in Java is a non-access modifier that can be applied to variables, methods, and classes. It is used to restrict the user from further modifying the entity to which it is applied.
🌐
W3Schools
w3schools.com › java › ref_keyword_final.asp
Java final Keyword
The final keyword is a non-access modifier used for classes, attributes and methods, which makes them non-changeable (impossible to inherit or override). The final keyword is useful when you want a variable to always store the same value, like ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-final-and-abstract-in-java
Difference between Final and Abstract in Java - GeeksforGeeks
July 12, 2025 - The main purpose of using a final class is to prevent the class from being inherited (i.e.) if a class is marked as final, then no other class can inherit any properties or methods from the final class.
🌐
Kotlin Discussions
discuss.kotlinlang.org › language design
Classes final by default - Language Design - Kotlin Discussions
June 28, 2015 - I understand the reasoning provided here: "By default, all classes in Kotlin are final, which corresponds to http://www.oracle.com/technetwork/java/effectivejava-136174.html">Effective Java, Item 17: Design and document for inheritance or else prohibit it." In practice, I find that this introduces an annoying level of friction with frameworks like Spring.
🌐
Quora
quora.com › What-is-final-class-in-Java
What is final class in Java? - Quora
Answer (1 of 7): If a class is declared as final, then it becomes final class. A final class cannot extend to another class. So we cannot access variables, methods present inside a final class to other class.
🌐
CodeGym
codegym.cc › java blog › keywords in java › java final keyword
Final Keyword In Java
January 14, 2025 - It can be applied to classes, methods, variables (including method parameters). For a class, the final keyword means that the class cannot have subclasses, i.e. inheritance is forbidden... This is useful when creating immutable (unchangeable) ...
🌐
Quora
quora.com › What-is-the-use-of-the-final-class-in-Java
What is the use of the final class in Java? - Quora
Answer (1 of 7): Sometime you do want to prevent your class to be extended further. * Immutability: If you want to create a java class immutable, you need to make that class final. Immutable class is needed in java for sharing an object in multi-threaded environment. In map like data structure,...
🌐
Programiz
programiz.com › java-programming › final-keyword
Java final keyword (With examples)
Once any entity (variable, method or class) is declared final, it can be assigned only once. That is, the final variable cannot be reinitialized with another value ... In Java, we cannot change the value of a final variable.