Java Interview Question #2 : Can Java inherit Final Method ?
Que 2. Can we inherit Final Method ?
Answer : Yes
In case of final method, Method is inherited but cannot be overriden so always method from parent class will be executed.
Consider the following example -
package com.c4learn.inheritance; public class ShapeClass { final void setShape() { System.out.println("I am Inherited");; } public static void main(String[] args) { Circle c1 = new Circle(); c1.setShape(); } } class Circle extends ShapeClass { }
Output :
I am Inherited
We can inherit the final method but cannot override the final method inside the child class.