Can a class in Java be both final and abstract?

Java 8Object Oriented ProgrammingProgramming

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.


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");


C:\Sample>javac error: illegal combination of modifiers: abstract and final
final abstract class Demo{
1 error
Published on 29-Dec-2017 04:31:30