Abstract vs final method in java

An abstract method must be overridden in the sub class whereas final method cannot be overridden.

Example: abstarct method overridden in subclass

abstract class AbstractMethodTest{
	abstract void show();
 
}
public class Main extends AbstractMethodTest {
    void show() {
        System.out.println("Inside overridden show method");
    }
	public static void main(String args[]){
		//creating object of Main Class
		Main obj = new Main();
		obj.show();
	}
}

Output

Inside overridden show method

Example: abstarct method overridden in subclass

abstract class AbstractMethodTest{
	abstract void show();
 
}
public class Main extends AbstractMethodTest {
 
	public static void main(String args[]){
		//creating object of Main Class
		Main obj = new Main();
		obj.show();
	}
}

Output

Main.java:5: error: Main is not abstract and does not override abstract method show() in AbstractMethodTest
public class Main extends AbstractMethodTest {
       ^
1 error

Example: final method without overriding in subclass

class FinalMethodTest{
	final void show(){
		System.out.println("w3schools.com");
	}
}
public class Main extends FinalMethodTest{
	public static void main(String args[]){
		//creating object of FinalMethodTest Class
		FinalMethodTest obj = new FinalMethodTest();
		obj.show();
	}
}

Output

w3schools.com

Example: final method overridden in subclass

class FinalMethodTest{
	final void show(){
		System.out.println("w3schools.com");
	}
}
public class Main extends FinalMethodTest{
    void show(){
		System.out.println("Overridden method");
	}
	public static void main(String args[]){
		//creating object of FinalMethodTest Class
		FinalMethodTest obj = new FinalMethodTest();
	}
}

Output

Main.java:7: error: show() in Main cannot override show() in FinalMethodTest
    void show(){
         ^
  overridden method is final
1 error

Java interview questions on final keyword