
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 Class in Java Be Both Final and Abstract?
An abstract cannot be instantiated. Therefore to use an abstract class you need to create another class and extend the abstract class and use it.
If a class is final you can't extend it further.
So, you cannot declare a class both final and abstract.
Example
Still if you try to do so you will get a compile time error saying "illegal combination of modifiers:"
final abstract class Demo{ public final void display(){ System.out.println("Hello welcome to tutorialspoint"); } }
Output
C:\Sample>javac Demo.java Demo.java:1: error: illegal combination of modifiers: abstract and final final abstract class Demo{ ^ 1 error
Advertisements