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