
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can a final class be subclassed 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{ }
Output
C:\Sample>javac Sub.java Sub.java:7: error: cannot inherit from final Super public class Sub extends Super{ ^ 1 error
- Related Questions & Answers
- Can a class in Java be both final and abstract?
- Why can't a Java class be both abstract and final?
- Can a constructor be made final in Java?
- Final class in Java
- Make a class final in Java
- Can constructors be marked final, abstract or static in Java?
- Can a final keyword alone be used to define a constant in Java?
- Why a constructor cannot be final in Java?
- Why Final Class used in Java?
- Can a final variable be initialized when an object is created in Java?
- Can a method local inner class access the local final variables in Java?
- Why constructor cannot be final in Java
- Can we inherit a final method in Java?
- Can private methods of a class be accessed from outside of a class in Java?
- Explain final class and final method in PHP.
Advertisements