can we use abstract and final both with a method?

No, as for an abstract method we have to provide implementation in subclass. To do this abstract method have to be overridden but final methods cannot be overridden.

Example

abstract class Show{
        //abstract final method declaration
        abstract final void show();
}
public class Main extends Show
{
	public static void main(String[] args) {
		System.out.println("Hello World");
	}
}

Output

Main.java:10: error: illegal combination of modifiers: abstract and final
        abstract final void show();
                            ^
Main.java:12: error: Main is not abstract and does not override abstract method show() in Show
public class Main extends Show
       ^
2 errors

Java interview questions on access modifiers

Please follow and like us:
Content Protection by DMCA.com