No, abstract class can’t be final in Java because abstract classes are used only by extending and if they made final they can’t extended.
Example
final abstract class DisplayTest { abstract void display(String str); } public class Main extends DisplayTest { public void display(String str) { System.out.println("Hello " + str); } public static void main(String[] args) { DisplayTest displayTest = new Main(); displayTest.display("w3schools.com"); } } |
Output
Main.java:1: error: illegal combination of modifiers: abstract and final final abstract class DisplayTest { ^ Main.java:7: error: cannot inherit from final DisplayTest public class Main extends DisplayTest ^ 2 errors |
Java interview questions on interface and abstract class
- What is interface in java?
- Can we declare an interface method static in java?
- Can an interface be declared final in java?
- What is marker interface and how we can create it?
- What is difference between abstract class and interface in java?
- What is abstract class in java?
- Why abstract class is used in java?
- Can abstract class have constructors in java?
- Can abstract class be final in java?
- Can we declare local inner class as abstract?