
final Keyword in Java - GeeksforGeeks
Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more., Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
geeksforgeeks.org →In Java, the final keyword is used to restrict changes and make code more secure and predictable. It can be applied to variables, methods, and classes to prevent modification, overriding, or inheritance. This helps in creating constant values, stable methods, and immutable classes. Final variables hold a value that cannot be reassigned after initialization. Final methods cannot be overridden by subclasses. Final classes cannot be extended. Initialization rules require that a final variable must be assigned exactly once either at declaration or inside constructors or initializer blocks. Reference final variables cannot change which object they point to though the internal state of the object can change. Static final variables represent constants shared across all objects. Blank final variables are declared without initialization and must be assigned once before use. Local final variables inside methods must be initialized within their block. Final classes are useful when creating immutable classes such as String or wrapper classes.
Excerpt from a page describing this subject · 12,450 chars · not written by Vinony
via Wikidata · CC0
Discovered by embedding cosine similarity (sentence-transformers MiniLM, 384-dim).