Final method in java

In java, final methods are declared with final keyword. We can not override the final methods.


class Show{
    //final method
	public final void show(){
		System.out.println("Inside final method");
class FinalMethodTest extends Show{
	//try to override final method
	public void show(){
		System.out.println("Inside overridden final method");
public class Main {
	public static void main(String args[]){
		//creating object of FinalMethodTest Class
		FinalMethodTest obj = new FinalMethodTest();
		//method call;

Output error: show() in FinalMethodTest cannot override show() in Show
	public void show(){
  overridden method is final
1 error

Java interview questions on final keyword

Please follow and like us:
Content Protection by