Can You Use Abstract and Final Both With A Method In Java?

No, We cannot use abstract and final keywords togeteher with a method because abstract method is meant to be overridden in subclass. If we declare abstract method as final it cannot be overridden in subclass. Therefore, it is not possible to declare abstract method as final. If we try declaring an abstract method final in Java it will result into compile-time error.

Following piece of code will generate a compile-time error.

class abstract TestAbstractFinalMethod {
	public final abstract void anAbstractMethod();
}
 
class Test extends TestAbstractFinalMethod {
	@Override
	public void anAbstractMethod(){
		// TODO Auto-generated method stub
	}
}

Above program will throw compile-time error: The abstract method anAbstractMethod in type TestAbstractFinalMethod can only set a visibility modifier, one of public or protected.

Hope we have enjoyed reading this post. Please do write us if we have any suggestion/comment or come across any error on this page. Thank we for reading!



Share this page on WhatsApp

Get Free Tutorials by Email

About the Author

is the founder and main contributor for cs-fundamentals.com. He is a software professional (post graduated from BITS-Pilani) and loves writing technical articles on programming and data structures.