- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are final classes in Java?
The final modifier for finalizing the implementations of classes, methods, and variables.
The main purpose of using a class being declared as final is to prevent the class from being subclassed. If a class is marked as final then no class can inherit any feature from the final class.
You cannot extend a final class. If you try it gives you a compile time error.
Example
final class Super { private int data = 30; } public class Sub extends Super{ public static void main(String args[]){ } }
Output
Exception in thread "main" java.lang.Error: Unresolved compilation problem: at newJavaExamples.Sub.main(Sub.java:9)
- Related Articles
- Why are classes sometimes declared final in Java?
- What are Java classes?
- What are abstract classes in Java?
- What are inner classes in Java?
- What are wrapper classes in Java?
- What is blank final variable? What are Static blank final variables in Java?
- What are anonymous inner classes in Java?
- What are I/O classes in Java?
- What are Java parent and child classes in Java?
- What are method local inner classes in Java?
- What are the different types of classes in Java?
- What are final, abstract, synchronized non-access modifiers in Java?
- What are the differences between Java classes and Java objects?
- What are the different types of nested classes are defined in Java?
- Why variables are declared final in Java

Advertisements