Can a java abstract class method be final and abstract both?

Answer: No, an abstract class method cannot be final and abstract both in java e.g.

abstract class A{
	
		final abstract void f() ;
	
}

Reason is that, by making a method final in abstract class, we are stopping derived class not to override and implement it. Whereas, by making it abstract, we are forcing derived class to override it and implement it. So, making a method both final and abstract is contradictory. Hence, using both final and abstract method does not make any sense.
Secondly, final method must have a body whereas abstract method can have only declaration. So, it is also contradictory.

abstract class A{
	
	/*
	 * final method in java programs means, a derived class cannot
	 * Override and implement it and it must have
	 * body/implementation
	 */
	
	final void f() {
		
	}
	/*
	 * abstract method in java must not have body
	 * means, no implementation.It will be
	 * Implemented by derived/ subclass
	 */
	
	abstract void f2();
	
}

If we use both final and abstract before method, then compiler will flash a compile time errors.

Related Posts